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 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 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 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 destroyer(arr) { | |
var args = Array.prototype.slice.apply(arguments).slice(1); | |
for (var i in arr) { | |
for (var j in args) { | |
if (arr[i] === args[j]) { | |
arr.splice(i, 1); | |
} | |
} | |
} | |
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 where(arr, num) { | |
newArr = arr.sort(); | |
finalArr = []; | |
for (var i = 0; i < newArr.length; i++) { | |
if (num > newArr[i] && num < newArr[i+1]) { | |
finalArr.push(newArr[i]); | |
finalArr.push(num); | |
} else { | |
finalArr.push(newArr[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 sumAll(arr) { | |
function getMaxOfArray(numArray) { | |
return Math.max.apply(null, numArray); | |
} | |
function getMinOfArray(numArray) { | |
return Math.min.apply(null, numArray); | |
} | |
var max = getMaxOfArray(arr); | |
var min = getMinOfArray(arr); | |
var n = max - min +1; //quantity of numbers to be added. |
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 diff(arr1, arr2) { | |
function getDiff(arr1, arr2) { | |
var newArr = []; | |
for (var i = 0; i < arr2.length; i++) { | |
if (arr1.indexOf(arr2[i]) === -1) { | |
newArr.push(arr2[i]); | |
} | |
} | |
return newArr; |
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 convert(num) { | |
//I V X L C D M | |
var roman = ''; | |
var counter = num; | |
while (counter !== 0) { | |
console.log(counter); | |
if (counter >= 1000) { | |
for (var i = 0; i < Math.floor(counter/1000); 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 replace(str, before, after) { | |
var newStr = str.replace(before, after); | |
if (before[0] === before[0].toUpperCase()) { | |
var afterArray = after.split(''); | |
afterArray.splice(0, 1, after[0].toUpperCase()); | |
var newAfter = afterArray.join(''); | |
console.log(newAfter); | |
newStr = str.replace(before, newAfter); |