Conquering freeCodeCamp - JavaScript Intermediate Algorithm Scripting (Part 1) - Live Stream #20

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello hello and welcome everybody who joined in this livestream where we're going to go over the next section in our quest to conquer free code camps curriculum this will be a tougher one because we're going over the intermediate algorithm scripting let me zoom in here so you can see better we did the basic one two days ago it was okay but we still I mean not wait I still failed some of them well we finished it somehow but it was yeah and also if we finish this we only have one more left to get the certification oh that's cool welcome everyone in the light chat and welcome for those of you who are watching the recording later all right I'd say that we should start there are 21 problems today your challenges and they are not that easy so yeah hopefully I'm going to be able to finish all of them in this livestream if not then I'll do another one depending on how how it will go all right let's start and see what is it about okay these challenges should prepare you to complete the final challenges all right so apparently the final ones will be harder okay this challenge will allow you to test how much you have learned and which parts you may need to review again before starting the project okay yeah one more thing before we start if you haven't done this before these challenges I suggest you give them a try on yourself because this is the best way for you to learn to try it first and see what solutions you come up with and then you can look over this recording and see what I did my solutions might not be the best you may find something which is faster or simpler whatever so don't think that I have the best solution all right with that out of the way let's see the first one some poll numbers in our range okay we'll pass you an array of two numbers return the sum of those of those two numbers plus the sum of all the numbers between them the lowest number will not always come first all right for example sum all week four and one should return tap okay this looks but so difficult so first we need to see we need to sort them first right we did a sorting algorithm yesterday I mean just a function we passed in so let's see let's save this sorted array we can do a rate that sort one thing I want is to console that lock this so we can see always what's the return here and we can pass in the sorted array which is now sorted by default but let's put for n1 which will also be sorted because there one letter the one digit numbers but he could pass in ten and five like here and they want to be sorted we discussed about this yesterday's livestream why they are not so let's create the compare function takes a and B and returns a minus B and then we can pass this compare function to our sort method and now it will work okay so with this out we can let's see let's create a for loop that's the simplest thing for let I will be the first element and it will go up to the or 70 0 up to array of what Oh sorted array will change the name and I plus plus now we can create this sum which would be zero and we can do some plus equals I write because I will be first the first number and it will go up slowly to the last number let's see the sum we should get 45 here good if we pass in 1 & 4 we should be at 10 and they should be done all right yet next one if two arrays compared to arrays and return a new array with any items only found in one of the two given arrays but not both in other words return the symmetric difference of two arrays okey-dokey let's see we can look over one array check if every item in that array is in the secondary with index off right hello welcome the live swing so let's do that a bird let's see which one array should we go over I guess it doesn't rip after good so let's do four or each loop on the very one we have the item and we can say if array to so the next the second array index of item is bigger than minus 1 so minus 1 will be it's not in an array yeah but that's what we want to test so it is minus 1 then we want to pass in in the new array numerator push item 8 right yeah although is one push all of the items because the secondary might be longer all right yeah it doesn't work for all of them then we need to I mean we could do this one more time but with the other way also might not be the best case but yeah this should run front end top he said they seem to be ordered yeah this D is one yet they are but look at these they are so we can we can by using the orders look at this they have numbers and so this is one approach [Music] would be to use find here and I guess this would work in the south let's see how we could do this with only one run we can basically see the length of the race so we can do something like everyone that length is bigger than array to week around dysfunction this loop and else we could run this so now we don't we avoid doing two loops and it should work let's see okay apparently doesn't twice that Oh rate to that length hmm if the first one then goes over all of them oh no but yeah it the item might be in the secondary it won't be in the first one so we won't see that so we need to go over all the power all of the Power Man front-end purposes but this is Oh and times ten he added through it's not the best solution so let's just go with it now if you find a better solution you can post it in the comments so we can take a look there seek and destroy you will be provided with an initial array the first argument in the destroy function followed by one or more arguments remove all elements from the initial array that are of the same value as these arguments okay we learned about rest parameter so we can use here the rest parameter to take all of the inputs for all of the parameters arguments one or two I think I thought not the different forget a different okay so now we have if we cancel that log rest you can see that oops eternal rest and console that lock here you can see that we have two and three if we pass in four we have two and three or four all right and now we just need to return an array you have to use the arguments object but I use the rest let's the go with this and then we can try to use the recommend subject although we haven't learned about it the in the curriculum so far so yeah remove elements for the initial array that are of the same value as the smokey so we can do array filter and you what we get the item and want to remove those that are in the rest array so we can say rest that index of pi term is greater than minus one so if this is greater and it is another array so it will be filtered all right you can see here we only have direct items which are so we can say again equal triple equals to minus 1 and then it will remove those okay this should work yep let's see we're up for two all right make a function that looks through an array of objects for cut first argument and returns an array of all objects that have matching name and value pairs second argument matching aim and that each name and value pair of the source object has to be present in the object from the collection if it isn't not if it is to be included in the returning array for example we have one of Kahless right and you master tune the third object from the array because it contains a name and its value that has passed on as the second argument all right so we need to loop over all of these objects and we going to find the property value the property name and if it matches the property of that I guess the second parameter could be yeah now yeah could have two are two properties so we need to go over all of the properties okay we have here the rate and disarray so we need to find all of the property all right this will be a little tougher so that's election or each item in the collection then we want to go over all the keys of the source so for let of key in source this would way we go over all the objects all the properties of the source object and if source II let's see this is the property so if we have this property if item of source he if I item that key sorry I turn that key if we have it and if item key will be equals to source key then we want to push inside the array so array that push item I guess this should work yeah so we cutting that is of this second array and we're checking if the item has this key or the property name and if it does we want to check in the value is the same as the value from the source if it is that we want to push the item let's see if this works okay apparently doesn't but why as a girl over all the let's see also that vlog last last last okay but what if we have the same but to us change it check in some pain [Music] let's copy dissolve like this oh but this has only one object want one week to Apple and cookies this one yeah you can see that this one doesn't s okay Apple cookie Apple cookie ever cooked and what's the issue basically we're checking the property one of the properties but we want to make sure that all of the property are so for that let's create a Pepsi you need to make sure all of the property so if it has three properties it should go inside three times right I'll let count be equal to zero and here we can increase the count all right and then at the end Eve I guess we can have to come round props should be increase it here because it will go over all the props and then let round equal props or pound props or whatever equal rub through the zero and this should be increased here so we cover all the properties in the source and then we need to check if all these properties are inside the collection and here if round props it will equal to well equivalent props equal to contracts then we want to push the item inside the ring all right now we fix the debt let's see all right works and we simplify this somehow and is it is it worth it [Music] I don't see now so let's go to the next spinal tap is but a string to spinal case final case is all lowercase words joined by dashes oh this is simple right we've kinda did this so we can split it all so that log let's see what happens so we split it by the space then we can map it all of the words we want were that lowercase like that and we can join it back with a dash I think that's alright not really look at that so we have Oh [Music] we have spaces we have dashes we have uppercase lower K underscores this will fix one but not the others now this becomes fun let's see we have space we have underscore uppercase and we have - you you now we could do it space lower case sorry space under all right forgotten space dashes and on others course we can do it with the rejects we have space fashion dashing the score this should probably work or he is but you Oh I faced in the right wrong thing it's would work for this yeah but then we have this case also yeah joy says that we can split with regex that's what I'm trying to do but we're also missing the this case won't work they just have to go over and find all the upper cases and we want to have an idea to easy yeah is it national since that will work but the problem is that we'll remove our see is yeah we will it will remove them right this is panel crap now but see what happens this is Pena and oh yes they say this is penalty' what I was thinking is that we can use a what I forgot house this house is called those please correct me and instead of splitting we can the place is with MySpace and also [Music] you there was this dollar one we had replacement was yeah group enjoys right so that's called grouping and then we could use booping' let's see if I put this and or that that doesn't work and with this dollar one it should have replaced [Music] you replace that [Music] let's go over to regex part again as we are allowed and a grouping specified check there was something I don't know which one it was a good place place oh yeah use capture room to search and replace yeah so can see here we had this group and then we can could replace it with dollar one that's what I was trying to do in replace rejects and replace text oh why on 2 plus a 2 Z e and bass wait one and space what [Music] interest this work or yes let's put it back and test it and we had oops also we need to needed to change B oh we added one cancel that love result you can see it swapped 3 2 1 this works drill as what i want to do is to find the uppercase how about splitting after replacing well yeah so basically I want to replace upper case with a space an upper case and then we can split and split it so we remove the space and then lower case you know that's in idea but apparently it doesn't work group Oh with this or so it works for the first one upper case this is not letter A to D okay yeah look at that so it works we just had to put it inside brackets so we can add a space before and now oh and G here so now you can see it it's adding spaces before uppercase letter oh that's fine now we can do our we fixed this and I guess this one too Surkov it to add a space and before but we can just three in that alright let's trim this we get rid of the first space and then we can also do split by let's see we have a group of space I mean non-lethal characters is back right II why do we have an empty string all the small thing but will this say Oh see it's a little island error yeah so we have a space there hey Patrick we're working with your favorite rejects and you want to figure out what's wrong here well I guess we can get with we can filter out all the spaces filter item item different then please we can we can map it item item to our case and then we can join back with a - this is the this is my solution but it's mmm way of being perfect well guess good work and Patrick says that his library has about for spinal case converter how did you do it oh so look this is not working the nd part I forgot ed let's see what it does or a and the Lord yes apparently it's not splitting well yep oh let's put it yep and a big up Big W here doesn't work for under key all right I very curious what you'll find find a better solution for it that will be great pig latin translate the provided swing to pig latin pig latin takes the first constant and cement or or the consonant cluster of an English word makes it to the end of the word and fixes it and a if the word begins with a vowel you just add a to the end if the word not when this vowel just add a to the end inputs things are granted to the English word in lowercase all right so we need to get all the normal box and put them yes right but how do we check if it's non vowel that's it I guess we can use it place and rejects again and it's like rejects let's see we want to take if it's not a vowel so can we say something like not a all the vowels also that vlog I'm cement not about s to start and it can be one or more I'll do say not they put it before a of the st. Patrick apnea I want to say it's not a Oh well this is the Asian eh eh let's look at that year that works and we need to make it a group so that we can do [Music] better one [Music] when do another group which will get everything and then we do dollar to okay look at that and we can say eh ah I like this if this works I'm pretty happy now I can be happy why let's see for our giri's and what it does as our Oh audio so it has to start algorithm okay but then if it's arts with then it won't do this so it won't change it won't add eight but basically I want to see if it's consonant the first put the first ones put it at the end and add a date but also let oh but we don't need to do this we just blaze replace your place replace it keep the world this is why I did this if it were it's the G it's the second under one there maybe here the dollar sign algorithm yeah but then if don't want add it well I guess we can add plus a here whatever at a four nationally for does California Kay bye okay or Nia EP PI step oh wait in California California oh it doesn't put it but they wouldn't do this now Oh clubs field doesn't work for algorithm Oh partly ah ha ha Phil not close we need yes and we have algorithm a emwi why oh if a war begins with a while Pawel you must just that way at the end oh boy so if it's a wall of a bowl then we need to add W [Music] you hey Tobias you're crying again alright let me put some water and then we can find it we can do a simple if else and do single detonation yeah that's right I wanted to be fancy with regex but apparently doesn't work like that I mean I I think Patrick can do it so if it's a vowel how do you check that if it's a constant you replace it with that it's a vowel you replace it with that you projects can get fancy but they can do logic inside them okay and I guess you can do if it starts with a non foul we the days let's see if thing up match let's save our regex is the thing if seeing that H projects and we do this oops right return stream let me copy this over motive and so we can check for California for paragraph or eight Okara for alone not month worker in match Oh regex that test right yes yeah we had regex that past the stream I had okay so he asked shouldn't if it parts with an on Val [Music] but then this hey Candace porneia yen sparks oh it should right and it should replace replace doesn't change the string yeah every place doesn't change all right so now this works I guess okay we can just so if it's not a console constant and we can do just Bing bus equals a like that ah a so we test by this regex and we can pause here we test by districts and place it if doesn't test then it's a vowel and we just add a yes this is a nice solution I'm very curious to see what they did yeah just don't check the solutions before you ate yours but this is an oval k imagine good place concat okay but pretty much to see a single zero match rejects LLC all right they run in the same place also not a lot different look at that almost 30 percent this goes this goes well search and replace rejects again hey I kinda start of like liking regex now that I understand how it works but I guess that it will leave I won't play around with it I'll forget Oh yep perform a search I replaced on the sentence using the arguments provided and returned on your sentence first argument is the sentence to perform the search and replace on secondary argument is the word that you will be replacing or third argument is what you will be replacing the second argument wait uhh reserved the case of the first character in the original word when you replay replacing it for example if you mean to replace the word pork with our dog it replaced as dog a so we need to find this word I replace it with this and having time with John we just need to make sure that we eat is it right so extreme that replace place before we after I guess lazy this would work for almost all of them but now we need to make sure that hi yes we can check if before zero and to see if it's uppercase how do you check oh yeah - we check if the lowercase the lower case is different than this let me think again so before that zero is the first letter if it's upper case and we lower case it then should be equal if before the lowercase means that it was uppercase and we lower kissing it oh yeah so if we lure kissing it and it was uppercase so this is upper case this is lower case if it's different and after zero should be after zero that upper k2 upper kit does this make sense to you or just my mind and now we can do this it should work let's see let's do this no I want this working and assigned read-only properties okay you so Candida right then we can do the string inking then let's just before will be before that's plate and after will be after that split so we're converting it to pray and before will be before joy has done today's video awful and after will be after that joint this is just the way to see if it works but now it's working that's it passes yeah but it's not the best all right after will be this is working with the race with it hence I just wanted to see if this particularly good one so after will be after zero to upper case plus after slice hockey be we don't need these names we can just do uppercase the first letter and an slice but we know in the chat if this makes sense to you if it is then I will go to next one if not I am going try to explain it again hmm all right I see no comment so apparently all of you are geniuses and I'll need explanation which is great I bet the or chip or smarter than me so that's good DNA pairing the DNS and is missing the parent element each character get its pair and return the result as a set to a regular 2d array base there are a pair of 80 and CG hey written provided for example for they put G's DC ABC Inc a chick that's e GC g return the pairs the character is para paired up in an array and all the arrays are grouped into one ask encapsulating array please explain I just I just go out the other one sorry sir please you might be behind the live stream but make sure you catch up s all right so we have the pair's of 80 and GT what I want to do now is to create an object which will have the property name be all of the letters and then we pair it with the air pairings let me do it in I'm going to explain I mean see and then we can just test if there's a we just SAT and with each day we say a at the DMV ro equally confused here first okay I'm going to go back and explain again now we have this string we can convert the string to an array with the split once all that fog you can see what you have you can see we have the pair now and we can just map over nicely and get the item and just return a nice object which will say the item as the property like the SI know either and then we say heirs of item as the vent so we're using the brackets here because we want the property value the property name to be this value item and then we're using this object to get the value of that property name so for example we have G here the first the property here in this object we're creating will be G and then its value will be from this object and oh so we need to return my rate all right so we need a trainer not enough check here we need an array and with two items in it the first one will be eight and see he is an array of we donate the brackets okay so something like I've got confused I talked to it they need an array of light I would not leave objects but they need an array overlay so then we item here we can pass in the item and the pair pipe as the okay let me go back to the previous one and try to explain I need to do it again Oh the issue we were having is that the second argument here you can see it has the uppercase as the first the first letter in the world it its uppercase so if that's the case we need to convert also this letter of the second the third argument in this case to uppercase I guess this makes sense because if we're having this we need to replace the word sleeping with the sitting word but with uppercase s so what I'm doing here is I'm testing if before zero so before zero is this word its first letter let me copy this so after so we're checking if this a to lowercase so we're converting it to lowercase is different then then this so let me so before zero now is uppercase s right we are lower casing it so we have lowercase s then if lowercase s is different than what is here that means that this is uppercase s right if this was lowercase s then before lower casing lowercase as we get the lowercase s right so only if it's different we want the after to be after zero plus after that slice 1 which will go over will add oh this one should be to uppercase and let's counsel that love this again so you can where if this is the case then we have an uppercase letter and we want to uppercase the first level of the after parameter and add in the rest with the slice but right here predictor Oh being that and we want to replace of a replace before we after all right I hope this time makes sense let me know Adriana and Spri if it does like over to the next one missing letters find the missing letter in the past letter range and return it yes if all the letters are present in the Ranger third undefined oh boy now this is interesting we want to go over all the letters from this string we want to see if we're missing one how can we do that one way is to convert the left turn into its ASCII value for those of you who are not familiar with the s cheat table basically all of the characters have an edge to value and we have ABC A to Z you can see a has a value of 97 that has a bed of 122 so we can go over our our string get the st value of the letters and then we can see if the next letter is not equal to the FIR the previous letter plus one and if it's not then we can just a which one is missing make sense it does my hand but let me know all right thing I mean that's great an array which would strain that splice that's split we convert the letters to or not we can we convert the string to an array and so that log we want to see what's returned here we returned array and we can see we have an array of letter then we want to map over and we want to return the SG value of all the letters to do that there was a metal char at so we have the letter and really turn letter char at zero now char at night was linked to chat let's see I forgot there is a [Music] convert to char s g f SP let's see I forgot that [Music] from char code now that will return the Charter chartered at oh okay so charcoal at char code at all right so this function let me put here in the second row this function will be will convert the chart code at zero in this case as it's one letter and it will return the value so you can see here we have 97 for Berkeley all right now we need to look over again do it that's Lily we can store property bullying now we don't need to so let's go for that I will be a raid 1 array of 0 and I will go up to array of array the flank minus 1 I plasters hello 1 keep them fine we're doing some challenges how are you so this will set the I to be the first element so 97 and it will go up to we don't need to go up to so like this up to the last value which will be 101 and then we're going to all of them now what we need to do is to check if I [Music] no I'm missing some no that's not good and I'm doing it wrong so we just need to go from I 0 to I Rea I had something in my mind but like that so we need to go over all the items and let's go sell them right i okay yeah that's good now and we need to check if array I plus one is different than array I plus one so the item at the current step plus one is different the item with the future step if it's different then we found the missing link a sig letter so we need to return here something we'll see what now one thing I want to do is to go - one here because we don't need to check the last item so [Music] one hundred and which one was that Donita 100 was it right yeah that's mom okay so we don't want to check the last item here in the array because we it's fine if we check this with this all right so now if it's different then we want to return its char code value right yeah a return from charcoal string.fromcharcode array of AI array of I plus one sorry so the next one which would be missing in this case D okay I guess yeah and this could be and the fact should be undefined if it doesn't return here so if it doesn't return that all of them are fine okay it works let me know who have any questions going to wait a little more or it might be a little confusing probably so we're going over all first we're converting the letters to their Charcot value then we're looping over the array getting all the items all the numbers in this case and we're checking if the item at this step plus one is different the item for them feature step if it is then it's not in is not the following letter if it's not the following later we return the char code st table value of that I mean we're converting the number back to the char code that's that's like hopefully it's in memory if this doesn't return here we just get on the plane so from charcoal does the opposite of charcoal death please converse back the number who it's letter so charcoal ad converts D here let's see so if you want the conversion from D to 100 char code ad converts D to 100 and from charcoal converts 102 D it's the vice versa entrance all right almost halfway there sorted Union Oh function then takes two or more arrays and return a new array of Union unique values in the quarter of the original provided during in other words all values present from all array should be included in their original corner but with no duplicates in an array the unique number should be sorted by their original order but the final array should not be sorted in numerical order of a this is a heavy one we need to go over and put it inside an array and if it's not there let's see we go over this array we put 1 3 2 over this one we put 5 we don't put 2 & 1 because they're already there what we put for and I'm here to one would put anything we don't put in okay so it's not that bad 1 2 3 5 - no no probably 4 to 1 no C 7 alright so it's not that bad alright let's put a rest parameter here so we get an array of all the rates also the bug here we can see there it to get an array over it I could try something crazy with reduce uhh let's do it Lee first we'll do it the [Music] simple way final array should be play and we go over left I mean we can do array for each in our array okay if final array now go over inner race here oh here we need another loop in our array for each item if final array includes this is another function we can use to find if the array as data if it doesn't include it then final array that push item they should part okay so it wasn't that hard we're looking through our bigger raid then we're looking through in array and if the item is not included in the final array which needs to be turn eight we're pushing it alright I think that's it the obvious I don't know why it said it's hard I had something else my mind let me do it with reduce videos we have the accumulator which will be turned and we have the current array in our array all right and we want to you I guess I'm going to go over the inner red inner array for E item this is not required adjust for fun uhh if accumulator includes so we basically do this part here dudes item so it doesn't include it and accumulated that push item and we just returned accumulator which will start an empty array okay so it works like that and we do it in one line not really I mean we can map over yeah it's fine so both of them are valid next forward HTML entities over the characters double codes and assumed in the string of their corresponding HTML okay so we get all the HTML entities or I'd need to find them [Music] let's see ampersand HTML you less than this last thing is this and have bigger than it's greater than then we have both which Oh and we have angle code which is up boss yep and we have the this which is what em well we had it here also and went right you've gotta find them you can easily do a rejects here look Lacey yeah that's what I was saying so let's create a an object with the property name being all of these and the value should be what we were earning we want to replace it I think I can in emoji is add both rounded around it here and well this for oh this won't work for this for I guess we can put this one all right now if we return our fancy object and it's reliably yeah and we'll have a sort of to this work okay and what I was thinking is to do for flat char the left key in replace whatever the object is all dinged up with place a key with the ripple key and we understand oh we need to store it back okay I'll be basically looking over all of the keys of this objective created and we're replacing that key the left side here with the key property the right side okay would return but what I guess it doesn't be based off to place all is that function they played them off let's see yes it only plays the first yep so how do we replace them all replace oh I guess a new passive of property of the kinetics when you pass a variable inside the regex was a way Betsy s variable to rejects oh look at that I searched for it replace red Jackson plays G you dynamically you [Music] okay yeah so we can do new rejects like that egg you stackoverflow so we can create our regex and it will take in the and it will do globally oh then we're passing our regex and look at that now it replaces all of them because we needed this D flag so it will find all of them okay not perfect yet why Oh Oh but wait I forgot to add am i : yeah yeah you know it works some are some are odd people 1900 people we need to find a civil nutty first even a positive integer return the sum of all odd Bonacci numbers that are less than or equal to none the first two numbers in the Fibonacci sequence are 1 and 1 every additional number in the sequence is the sum of the two previous numbers the first six numbers of the Falacci sequence a 1 1 2 3 5 a [Music] last boy we need to create to get all the Fibonacci numbers add them up until we have a number that's less than the given number okay you I know why I created a Fibonacci calculator so we have first one we have the second one and let's add some and while the sum is greater than number we want to do uh a will be e and b will be a plus B we need to store the temporary fur so 10 on stamp will be a a will be B and B will be temp us if and then some will be a plus right yeah and we return the some as this part yep I'm not sure what's the number we need to start with oh let's see four thousand zero all right let's start from great that Oh while some less than okay we have a number but it's not the correct number maybe some should start with a plus E [Music] pepper is a a will be be and they will be a plus B and then we add in Oh some not equal some plus equal okay now wait again wait a minute compass equals B but the last one what's wrong something's wrong start to lose my impression we did a couple one hour and 30 minutes okay so that's in a while written the sum of odd odd odd odd what an odd okay because of these thoughts oh boy so we only need to add the number if it's odd okay Oh plus equals is B modules is B modulus 2 equal to 0 we're doing the third area here if it is then we add B otherwise we add zero all right at but it's not the best of its module still than odd that's odd what's the odd number odd numbers odd even Oh also different than different than zero okay close we need to add here one and one so a plus B a look at that we got them okay this number should be that number what blue what number is that Oh I guess it shouldn't add it only if it's - second first return the sum of all odd numbers that are less than or equal to now okay so not the sum should be less than but be you it's or that it works for this number but not for this I guess it just adds it'll because it's odd at odd now it's not that defriended Oh yeah good I guess I can do a check if B is greater than you if B is less than yeah so we only add them if B is less than equal because it might go again I guess this should work Oh that's weird I wanted to do the check here also oh wow I don't doubt that some all crimes alright another fun stuff we have people not Chino primes a prime number is a whole number greater than one with exactly two divisions one itself for example two is a prime number or is not because divided by two Oh first let's create a function is Prime we pass in a number and we need to return something we can return true but we need to do a check for let I equals to I plus plus I less then half of it or square root of it I forgot which was the middle point let me write this in wait if number division modulus I is zero then we divide them with the term false because we found a number which is divisible with that number so for example we have 4 it goes here it will start with 2 and it will check he is divisible with two if it is so then it's not right if we have five it will go to it will test with two three and four no it won't rest with fourth we don't test with two because we have the square root the reason I do the square root is because it's not necessary to go up to the number I think it's care square root or half of it something like that because if you have 17 is no point to go over checking over 6 no 6 of the square root if this is something I learned so you should load it with if it will work also that log sum of primes it will rewrite sometimes which returns the sum of all prime numbers that are less than or equal to now okay so const let some absolute zero for let I are sweet one I less than equals to the number five plus plus so now we go from the from one to the number we are given and if is prime the number we want to sum it up you something like puzzler Peace Prize Oh is prime I sorry as we're using I to keep track of the number and through 670 up to less than or equal to now yeah the some all prime numbers that are less than or equal to less than or equal let's test our risk prime function also that log is prime 70 1600 k9 - eight - eight but I guess here we should go just up to oh yeah it's okay because it's not pride but mine was brown 9 is prime is not prime because division by 3 so up to square root okay let's go up to the athlete I'm not sure what we're head square root in mind some reason uh kick bill wrong everyone anyone watching still messing things up what is recording what was 80 why adds one to the dead one you so I guess it could start that's weird so they say returns all right so if there's the sum of all prime numbers at 11:01 is not prime is it one deserves fancy numbers or not prime okay okay okay let me try work with Methodist dirty I have something we test clarity for some reason yeah so it doesn't have to do go up to the half of it just square root of it which is left so it's a sum the reason I know about it is because I did this while ago and I know that if you go up to half of it will be longer than it could go up to square root like right so you save some loops there all right smallest common multiple I don't like sound of this I'm the smallest let's see how many we have left eight okay and we do it in half an hour smallest common multiple find the smallest common multiple of the provided parameters that can be evenly divided by both as well as by all sequential number in the range between these parameters arrange will be an array of two numbers that will not necessarily be in numerical order for example if one and three find the smallest from a multiple of both one and three it is also evenly divisible by all the numbers between one and three the answer here will be six one two three I guess we can and mouth now because we need to find the smallest now that's art one I know there is a formula for essence is the smaller comma [Music] smallest common multiple least comment there is a function this one [Music] but we need the greatest common devisor not all over yeah for loop but it can go over and multiply them all but then it's not the smallest I can do something it would be silly I can multiply them all and then loop over all the numbers and find the smallest like that it won't be the best but I have no idea how to do it otherwise now so I guess we'll roll with what we have yeah that's just we can find the product by using a reduced rate reduced we have accumulated and the item or the number and we do a cumulated multiplied with the number start with one now the product we'll be there multiplication we need to need all the numbers so we need to create a new array and for let I equals our old array and it goes up to the value operating day one and now new array push I so now the new array should be dis okey so we now have the product of all the numbers from one to five one times two three four five okay good and I guess we need to go over all the numbers now yeah all the numbers from 1 to 120 and see if they divide equally psychic number if they are then we return and this is what they have now so it's not the best by far I will be one I guess we can save a few loops by going to the last night oh well yes I less than or equal to our product my plus plus and now we need to [Music] overall the items so new array or or each we can do a 4-h we can do a filter the other number and we want to see if number modulus I is zero oh it's the if is divisible with this number Oh No look oh yeah it's okay to get if I is divisible by this number so the I in our case could be 60 for example and we if we say if I or 60 is divisible by number which will be 1 and is divisible by number two divisible by number three okay so this will return the array of all the elements that are divisible by this number and we can check and get constant length of this filter and if the length of this filter let's colleges to them if the length of this filter will be equal to the new array at length oh if it won't filter anything out then it means that all of them are divisible right so if it won't filter out the new array length will be the length of the filter elements if it that's the case then we return Inaki apparent it it done at NBC we get the number we get I visual numbers zero let's cancel that length oh okay okay okay so we get the right here we need the length of this array all right good all right look at that we have 60 we also have to check if array zero bigger than a one if yes dance pop oh yeah that's right good point very good point thank you so if array 0 greater than array 1 we want to do this array but 23:1 will be praise 0 and raid 0 will be 1/10 value which and will be array we're swapping the item because if we're checking this now it should work amp is not defined okay I guess the constant should look so without this check it will be one because it won't get all the items thank you great good so now it should work yeah it's very slow because this is not how you should do it you should use the O's SMM formula and then find the commas most common multiple of all the number yeah it's an a3 the server to update your progress by don't let me lose this it work okay it is good who was a harder one they get hardware hardware appearing all right given the array iterate through and remove each element starting from the first element in the zero until the function returns true when the iterate element is passed through Victor the parrot and the rest of the rate once the condition is satisfied all right so basically we want to - a filter but I mean we need to find the we need to find the first element for which this condition returns through and then just return back the array parting the death index so it this should be fine we need the index and we can get it by saying already find dysfunction finding this and then we turn Array slice bond is not so this is easy with array methods we learned yesterday yes so bigger than five to return em today oh okay like that if it finds it or otherwise zero raid at length minus one so we need Oh oopsie oh if it doesn't find it then it should return an empty Oh if what seen also that Clause X or this one because the functionary defines it the end bigger than five and doesn't find anything so we should you just return an empty um you what's wrong us Oh not constant that I refer back to ahead the drop function is removed okay - one alright so we can check if index is minus one we want to just return an empty array otherwise we do the slicing now this should work for our specialty okay next Stream steamroller flatten a nested array you must account for varying level or nesting he all right I think we can use the flat method left was a new method in let's see a flat [Music] jealously at you well smoothly a flat third yeah that's it function flat but it only works for one level deep arrey lat all levels oh we pass in the depth defaults to one but how do we know the depth Oh infinity okay and you should not use a reflector that was really fun I thought I'm good I thought the time getting away with it but apparently not yeah using pet is not allowed oh boy all right I'm upset now while not allowed it would be so easy Oh flat map flatmap I think is the new one that map Edler function is not callable why oh well anyway yeah that would be such a nice solution I guess we should go over the race and yes find if it's and pray and if it is we need the inner value we can write our own as if can we at this time Empire II and you can see here that this one it turns one two three this one returns the object also so yeah they remove the empty array Oh can't use flap I can't help it we try to do using the coercion and what happened I [Music] a guess that adriĆ  and hello the description thank you for subscribing I guess let me try to hack you history no no you answer a [Music] ah answer a flat pencil a flat a and never mind I'm just fooling around with and the good with prototype a all right let's do it the old way we need return very so between em period and array for each item inside they think it needs a closure is someone clever enough in the act only how to bewitch weaker flat yep tonari here if array [Music] yeah Joey that will work but only one level live what you sent let me show you um cat you see so it does the same as uncapped array you only works one level Li haha hey hey mrs. Weber so we need a base condition for our recursive function it will uhh if array if this is not an array and we want to return item otherwise bitter otherwise return the call of flattered wait I come this and after that's what they do oh yeah if I raise array so if it's array if it's not an array we return the item but if it is then we want to return item at level X 0 I guess but won't work if there are multiple up let's see also that vlog a flat turn arranged yeah you can see it goes for the first one if we put array of what at undefined no not good you I think it will work for this one because it has elements like in death you let's think we need to go over all the elements inside the array if they are arrays we want to remove the array you dysfunctional we build Oh yeah and see it works for the first one not for the and one I guess we can do now for each less than I am Betsy Wacha a be okay we get a and B what about this one two three with why item with oh because this one has double about travel we can take care of that also it won't work for this one as we want to reveal it yeah equal so we doesn't work if disarray which is best here has multiple arrays you you don't need here zero you ever name you we carry a return of a of [Music] you don't remember doing this challenge I know it did a lot of JavaScript challenges that they don't remember how it did this I will be using flat but they didn't head the condition back then I could throw something asked our flat array.prototype left if they see me this [Music] athlete you Evan air reflected Oh function flag you Oh keep trying to hack the system not that probed wanted to copy the black method and then use our our own flat method because that will probably pass this test you okay I'm going to do the next one and we'll try again that uhh after work because I don't want to waste that much time now return on English translated centers two of the past binary string okay so I did I did the challenge I mean I did a tutorial on my channel exactly with this it should be pretty easy if I remember how I did it we get all the characters here and then we map over to convert them [Music] our end item 2 string - now there's a function which converted the number to letters you okay yeah the parson converts the number who eats a character value and then we can just do string.fromcharcode when they listened our code like that and we have the digits we can join back yay okay so we getting the st value with parseint because their binary and then we're converting them to characters using from jacquard okay this was easiest easier everything be true check if the crack predicate second argument is true T on all elements of the collection first segment in other words you are given an array collection of objects the predicate 3e will be an object property and you need to return through with this values through T in JavaScript to Tavares our values that translated through when related in boolean remember you can access object properties through either done a digital what you so we need to check if it has the property and don't understand the question or the challenge we have aged 0 o H 0 here okay yeah you know and this doesn't have it all right I think I know first we need to go over the collections of collection or each item let's see the item okay we have the items and now we want to do four let e in item if e equals three and oops item for KI and item of key then this is okay we want to check is not okay so if he doesn't otherwise return no apparently not but also that log key and I Tempe or left key nighttime we go over all the keys if the key is free a then we check if is pre and if the item ducky is through oh yeah Lupe's through if it is but if it's false then Little Falls oh we also need to check maybe doesn't have the property course we check if item II something it is then we go over or we don't need to go over no because starting to lose my concentration if not right on that key if it doesn't have that you as doesn't have his property and we tag pops if it does the K so when a third party doesn't have the property and return false if item of us is now defined a prick still good didn't understand the challenge check if the predicate is 30 on all elements of the condition oh if it's on all yeah but this goes over and if it finds one it returns false that should work in other words you're given an array of collection the predicate will be an object property and you need to return true if this value is true T otherwise it turn false if it doesn't have that property let's also log and see what it does okay okay so all of them have that and now we male male female female okay so this should be true it's true let's check for this which should be false why it's not false Falls undefined but we also this balls to go here and turn false why doesn't here okay so if those he had shooted turnip house here - whatever yeah it goes out excess the true male goes there through my goes there and there's but it is from this I need to return from the function bro let's convert these two before loop or but I 0 I less than collection length I plus plus and then I called item LD collection of I alright or this fast this type fine let them know now he should go out of the poor before look here here false okay yeah see after this it goes up all right so this is a lesson from the or each method if you return it doesn't doesn't do anything I guess and that's sure but it doesn't work as we wanted here at least that's what we know good next one humans optional hate the function then subs two arguments together if only one arguments provided then return a function that expects one argument okay so basically what we did of currying right so we need to we have X here return function which returns X X Y and X plus y now fredita five let's see I'll sew that clock it does a function function returns a function but then Oh yeah if only one onwards provided and return a function that expects one argument editors the son oh okay oh we have here amb if be if not be and we do this and repassing be and a oops rise we return a + b so you don't have the and we're returning of action which then will return a plus B as we tenemos well puncture and what case we have here should return undefined why if I direct isn't a very number return undefined okay number is integer and [Music] I mean we need to check number is picture and return like they are not numbers we return undefined if they are numbers but we don't have be return a function which expects me otherwise we return the calculation to return on the find and what does it return at either [Music] 23 you the integer number is not working interesting [Music] you oh oh and or it should be or oh if one of them is nothing there dammit okay we're still learning let's see what's not that together is not the function but Oh don't have the e or B is undefined we turn the function you this is not how it did with currying let's check and hurry functionary tell function but this is exactly what we did there why doesn't want to here be be unkind let's get there Oh if so if there is nothing here and be is nothing but here we don't have B so it won't be an integer and it will return undefined so we need to do this first and then this check will do here make sense because this was B was undefined so it wasn't an integer and it returned undefined and we can call the function undefined all right apparently now this doesn't @cy to return undefined let me get this auntie first-base I'm fine and it turns be oh we need to check for B Oh many checks if his number retired on the side okay and we have one more eight there's a function you but I did not obey them find it should go here okay goes here and [Music] expert you isn't find it a function X is embarrassing which is not integer then oh it returns a function as bees underside you did you check for a oh boy you I am now starting to just complicate this you I just did the checks for all of them which is not that good oops yeah please simplify and let me know how you did it make a person really in the object constructor with the following methods yet first name last name full name first name last name full name run the test to see they expect it out for each method the outputs that take an argument must accept only one argument and it has to be a string these methods must be the only available means of interacting with the object good so we need to make getters and setters [Music] you alright you know what I'm going to stop now because I'm tired and I'm going to continue tomorrow morning as I'm tired and I'm really done no no out I mean I know how to do it but we'll be just a aide thank y'all for watching ill now and see you tomorrow with the rest of them we have let's see one two three more so it will be probably a quick one lets see map to the base rent asunder elements it okay so some calculations let's see maybe we can do this tonight now new array that response elements average altitude into their orbital period named average you can read about orbit here the value should be rounded to the nearest whole number body being orbited earth the radius of the earth is that and the GM value is at above basically a calculation of all of them it should be easy if we find the formula ah orbital period in seconds two point masses calculated old to be a 3e you okay yeah I'm going to cover decent ro-beast also good egg your for staying up till now if you did if you didn't then shame on you and I'll see you tomorrow bye
Info
Channel: Florin Pop
Views: 6,783
Rating: undefined out of 5
Keywords: freecodecamp, learn programming, programming for beginners, live coding, live, live stream, programming tutorial, freecodecamp curriculum, florin pop, coding, coding for beginners, planning, coding tutorial, javascript, javascript tutorial, freecodecamp javascript, higher order functions, array functions, currying, javascript algorithms, javascript intermediate algorithms
Id: jSWT8myUYEY
Channel Id: undefined
Length: 133min 53sec (8033 seconds)
Published: Sat Feb 29 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.