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 bouncer(arr) { | |
| arr = arr.filter(function(ele) { | |
| if(ele) | |
| return ele; | |
| }); | |
| return arr; | |
| } | |
| bouncer([7, "ate", "", false, 9]); |
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 mutation(arr) { | |
| for(var i = 0; i < arr[1].length; i++) { | |
| for(var j = 0; j < arr[0].length; j++) { | |
| if(arr[0].toLowerCase().indexOf(arr[1].toLowerCase().charAt(i)) < 0) { | |
| return false; | |
| } | |
| } | |
| } | |
| return true; | |
| } |
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 slasher(arr, howMany) { | |
| arr.splice(0, howMany); | |
| return arr; | |
| } | |
| slasher([1, 2, 3], 2); |
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 chunkArrayInGroups(arr, size) { | |
| var result = []; | |
| for(var i = 0; i < arr.length; i+=size) { | |
| result.push(arr.slice(i, i+size)); | |
| } | |
| return result; | |
| } | |
| chunkArrayInGroups(["a", "b", "c", "d"], 2); |
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 truncateString(str, num) { | |
| if(num >= str.length) { | |
| return str; | |
| } | |
| if(num > 3) { | |
| return str.slice(0, num - 3) + "..."; | |
| } | |
| return str.slice(0, num) + "..."; | |
| } |
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 repeatStringNumTimes(str, num) { | |
| if(num < 1) { | |
| return ""; | |
| } | |
| return str.repeat(num); | |
| } |
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 confirmEnding(str, target) { | |
| return str.substring(str.length - target.length) === target; | |
| } | |
| confirmEnding("Bastian", "n"); |
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 largestOfFour(arr) { | |
| var result = []; | |
| arr.forEach(function(arr) { | |
| var max = arr[0]; | |
| for(var i = 1; i < arr.length; i++) { | |
| if(arr[i] > max) { | |
| max = arr[i]; | |
| } | |
| } | |
| result.push(max); |
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 titleCase(str) { | |
| var arr = str.split(" "); | |
| for(var i = 0; i < arr.length; i++) { | |
| arr[i] = arr[i].charAt(0).toUpperCase() + arr[i].slice(1).toLowerCase(); | |
| } | |
| return arr.join(" "); | |
| } | |
| titleCase("I'm a little tea pot"); |
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 findLongestWord(str) { | |
| var arr = str.split(" "); | |
| var longestWord = arr[0]; | |
| for(var i = 1; i < arr.length; i++) { | |
| if(arr[i].length > longestWord.length) { | |
| longestWord = arr[i]; | |
| } | |
| } | |
| return longestWord.length; | |
| } |