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
var endArr = [], | |
firstCap = [], | |
finalStr = []; | |
function theChopper(arr) { | |
for (var i = 0; i < arr.length; i++) { | |
firstCap.push(arr[i].charAt(0).toUpperCase()); | |
endArr.push(arr[i].slice(1)); | |
} | |
} |
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) { | |
for (var i = 0; i < arr.length; i++) { | |
for (var j = 0; j < arr[i].length; j++) { | |
arr[i] = Math.max(...arr[i]); | |
} | |
} | |
return arr; | |
} | |
largestOfFour([[4, 5, 1, 3], [13, 27, 18, 26], [32, 35, 37, 39], [1000, 1001, 857, 1]]); |
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
var count = 0; | |
function cc(card) { | |
switch (card) { | |
case 2: | |
case 3: | |
case 4: | |
case 5: | |
case 6: | |
count++; |
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 confirmEnding(str, target) { | |
var fragCount = target.length, | |
chunk = str.substring(str.length - fragCount); | |
if (chunk === target) { | |
return true; | |
} else { return false; } | |
} | |
confirmEnding("Walking on water and developing software from a specification are easy if both are frozen", "specification"); |
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 truncateString(str, num) { | |
if (num <= 3) { | |
str = str.slice(0, num) + "..."; | |
} else if (str.length > num) { | |
str = str.slice(0, (num - 3)) + "..."; | |
} | |
return str; | |
} | |
truncateString("Jason", 1); |
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
// Write a function that splits an array (first argument) into groups the length of size (second argument) and returns them as a two-dimensional array. | |
function chunkArrayInGroups(arr, size) { | |
var newArr = []; | |
beginSlice = 0, | |
endSlice = size; | |
for (var i = 0; i < (arr.length/size); i++) { | |
newArr.push(arr.join("").slice(beginSlice, endSlice).split()); | |
beginSlice += size; |
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) { | |
var str1 = arr.slice(0, 1).join(" ").toLowerCase(), | |
str2 = arr.slice(1).join(" ").toLowerCase(), | |
hits = 0; | |
for (var i = 0; i < str2.length; i++) { | |
if (str1.indexOf(str2[i]) !== -1) { | |
hits += 1; | |
} | |
} | |
if (hits === str2.length) { |
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) { | |
var newArr = arr.filter( function(el) { | |
if (el) { | |
return el; | |
} | |
}); | |
return newArr; | |
} | |
bouncer([7, "ate", "", false, 9]); |
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(args) { | |
var args = [...arguments] | |
, finalArray = [] | |
, targetArray = args.shift(); | |
finalArray = targetArray.filter(function(el) { | |
return args.every(function(arg) { | |
return ( el !== arg); | |
}); | |
}); |
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 getIndexToIns(arr, num) { | |
let numArr = arguments[0], | |
addNum = arguments[1]; | |
numArr.push(addNum); | |
numArr.sort(function(a, b) { | |
return a - b; | |
}); | |
return numArr.indexOf(addNum); | |
} |