You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
4. Basic Algorithm Scripting: Find the Longest Word in a String
functionfindLongestWordLength(str){returnstr.split(' ').reduce(function(accumulator,currentValue){returnMath.max(accumulator,currentValue.length);},0);}findLongestWordLength("The quick brown fox jumped over the lazy dog");
5. Basic Algorithm Scripting: Return Largest Numbers in Arrays
11. Basic Algorithm Scripting: Title Case a Sentence
functiontitleCase(str){varconvertToArray=str.toLowerCase().split(" ");varresult=convertToArray.map(function(val){returnval.replace(val.charAt(0),val.charAt(0).toUpperCase());});returnresult.join(" ");}titleCase("I'm a little tea pot");
functiongetIndexToIns(arr,num){varcount=0;for(vari=0;i<arr.length;i++){if(num>arr[i]){count++;}}// counts how many array numbers are smaller than numreturncount;// the above equals num's position in a sorted array}getIndexToIns([40,60],50);
15. Basic Algorithm Scripting: Mutations
functionmutation(arr){returnarr[1].toLowerCase().split("").every(function(letter){returnarr[0].toLowerCase().indexOf(letter)!=-1;//return true as long as the array contain all of the letters});}mutation(["hello","hey"]);