This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Find the longest single-word palindrome within a phrase. | |
| The phrase will only contain letters (no symbols, punctuation, or numbers). | |
| Your palindrome detection should be case-insensitive. | |
| If there are multiple longest palindromes of equal length, return the last one. | |
| */ | |
| function findLongestPalindrome(sentence) { | |
| // split sentence into words | |
| var b = [] | |
| var a = sentence.split(/\s/) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Flesh out the implementation and test it. | |
| Implementation of WHAT, you say? What's the problem statement??? | |
| Well, you should be able to tell what this code is intended to do just from reading the starter "skeleton". | |
| Assuming you find the above statement to be true upon reading the outline, well, then that illustrates the power of good outlining. You don't need a bunch of comments explaining the code. The code is effectively SELF-EXPLANATORY, even at this early, not-fully-implemented stage. This is the level of clarity that you should aim for in your own coding too. | |
| === |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //001 | |
| function transformFirstAndLast(array) { | |
| //your code here | |
| var a = {} | |
| a[array[0]] = array[array.length - 1 ] | |
| return a | |
| } | |
| //002 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fib(n) { | |
| if (n < 2) { | |
| return n; | |
| } else { | |
| return fib(n - 1) + fib(n - 2); | |
| } | |
| } | |
| // 1 0 | 1 1 2 3 5 8 13 21 34 55 89 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var c = [1,2,1,3,6,3,6,4,4,5] | |
| var f = c.filter(function(value,index,array){ | |
| return array.lastIndexOf(value) == index | |
| }) | |
| var unique = c.filter((v, i, a) => a.indexOf(v) === i); | |
| console.log(f) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var uniqueInOrder=function(iterable){ | |
| //your code here - remember iterable can be a string or an array | |
| var a = [] | |
| for(let i = 1; i<=iterable.length;i++){ | |
| if(iterable[i]!=iterable[i-1]){ | |
| a.push(iterable[i-1]) | |
| } | |
| } | |
| return a; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function likes(names) { | |
| // TODO | |
| if(names.length == 0) return "no one likes this" | |
| if(names.length == 1) return `${names[0]} likes this` | |
| if(names.length == 2) return `${names[0]} and ${names[1]} like this` | |
| if(names.length == 3) return `${names[0]}, ${names[1]} and ${names[2]} like this` | |
| if(names.length > 3) return `${names[0]}, ${names[1]} and ${names.length - 2} others like this` | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function findUniq(arr) { | |
| var answer = 0; | |
| arr.forEach(function(each){ | |
| if(arr.indexOf(each) == arr.lastIndexOf(each)){ | |
| answer = each; | |
| return | |
| } | |
| }) | |
| return answer | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class SmallestIntegerFinder { | |
| findSmallestInt(args) { | |
| return args.sort((a,b) => a-b)[0] | |
| } | |
| } | |
| // Math.min(...args) | |
| // Math.min(null,args) | |
| var a = [3,45,6,7,8,922,2,3] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function checkNumbers(array){ | |
| var counter = 1; | |
| var a = [] | |
| for(var i = 1; i <= array.length; i++){ | |
| if(array[i] != array[i-1]){ | |
| a.push("Number: " + [array[i-1], " Count: " + counter]) | |
| counter = 1; | |
| } else { | |
| counter++; |
NewerOlder