This file contains 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 where(collection, source) { | |
var arr = []; | |
var findKeys = Object.keys(source); | |
for (var i = 0; i < collection.length; i++) { | |
var currentObj = collection[i]; | |
for (var j = 0; j < findKeys.length; j++) { | |
var key = findKeys[j]; | |
if (currentObj.hasOwnProperty(key) && currentObj[key] === source[key]) { | |
arr.push(currentObj); |
This file contains 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) { | |
//callback function for filter method | |
function RemoveFalse (value) { | |
if (value === '' || value === false || value === null || value === 0 || value === undefined) { | |
return false; | |
} else { | |
return true; | |
} | |
} | |
return arr.filter(RemoveFalse); |
This file contains 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) { | |
newArray = []; | |
newArray[0] = arr[0].toLowerCase(); | |
newArray[1] = arr[1].toLowerCase(); | |
console.log(newArray); | |
var finalArray = []; | |
var numberOfLetters = newArray[1].split('').length; | |
for (var i = 0; i < numberOfLetters; i++) { | |
finalArray.push(newArray[0].indexOf(newArray[1][i])); | |
console.log(newArray[0].indexOf(newArray[1][i])); |
This file contains 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) { | |
if (howMany >= arr.length) { | |
return []; | |
} else if (howMany === 0) { | |
return arr; | |
} else { | |
arr.splice (0, howMany); | |
return arr; | |
} | |
} |
This file contains 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(arr, size) { | |
var count = 0; | |
var newArray = []; | |
var finalArray = []; | |
while (count < arr.length) { | |
newArray = arr.slice(count, count+size); | |
finalArray.push(newArray); | |
count += size; | |
} | |
return finalArray; |
This file contains 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 truncate(str, num) { | |
if (str.length > num) { | |
str = str.slice(0, num-3) + '...'; | |
} | |
return str; | |
} | |
truncate('A-tisket a-tasket A green and yellow basket', 11); |
This file contains 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 repeat(str, num) { | |
if (num <= 0) { | |
return ''; | |
} else { | |
var rep = str; | |
var i = 1; | |
while (i < num) { | |
str = str + rep; | |
i++; | |
} |
This file contains 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) { | |
var stringLength = str.length; | |
var targetLength = target.length; | |
var diffLength = stringLength - targetLength; | |
if (str.substr(diffLength) === target) { | |
return true; | |
} else { | |
return false; | |
} | |
} |
This file contains 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 largestOfFourArray = []; | |
console.log(typeof(largestOfFourArray)); | |
for (var i in arr) { | |
var largestOfCurrentArray = arr[i][0]; | |
for (var j in arr[i]) { | |
if (arr[i][j] > largestOfCurrentArray) { | |
largestOfCurrentArray = arr[i][j]; | |
largestOfFourArray[i] = largestOfCurrentArray; | |
} else { |
This file contains 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) { | |
str = str.toLowerCase(); | |
str = str.split(' '); | |
console.log(str); | |
for (var i in str) { | |
str[i] = str[i].charAt(0).toUpperCase() + str[i].substr(1); | |
console.log(str[i]); | |
} | |
str = str.join(' '); | |
return str; |