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 (n) { | |
return (n !== undefined && n !== null && n !== false && n !== 0 && n !== "" && n!== isNaN); }); | |
return arr; | |
} |
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
Return the remaining elements of an array after chopping off n elements from the head. | |
Here are some helpful links: | |
Array.slice() | |
Array.splice() |
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 chunk (array, length) { | |
var chunkarr = [], | |
i = 0, | |
n = array.length; | |
while (i < n) { | |
chunkarr.push(array.slice(i, i += length)); | |
} |
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
Truncate a string (first argument) if it is longer than the given maximum string length (second argument). Return the truncated string with a '...' ending. | |
Note that the three dots at the end add to the string length. | |
Here are some helpful links: | |
String.slice() |
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
Repeat a given string (first argument) n times (second argument). Return an empty string if n is a negative number. | |
Here are some helpful links: | |
Global String Object | |
The '&' is a Bitwise AND. >> is Bitwise right shift operator. Bitwise shift operators Operations to shift all bits of the operand. | |
Bitwise operators (&,|,^) treat their operands as a set of 32 bits (zeros and ones) and return standard JavaScript numerical values. |
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 end(str, target) { | |
return str.substring(str.length-target.length) == target; | |
} |
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
Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain exactly 4 sub-arrays. |
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
Make the first letter of each word uppercase and the other letters of the word lowercase. |
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) { | |
longWords = str.split(' '); | |
var longest = longWords[0].length; | |
for (var i = 0; i < longWords.length; i++) { | |
if (longWords[i].length > longest) { | |
longest = longWords[i].length; | |
} | |
} |
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 palindrome (str) { | |
var string = (str+'').replace(/[\.,-\/#!$%\^&\*;:{}=\-_`~\ ()]/g,"").replace(/\s/g, "").toLowerCase(); | |
return string === (string.split('').reverse().join('')); | |
} |