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 palindrome(str) { | |
str = str.replace(/[^a-z\d]+/gi, '').toLowerCase(); | |
var reversed = ""; | |
for(var i = str.length - 1; i >= 0; i--){ | |
reversed += str[i]; | |
} | |
return str === reversed; |
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 findLongestWord(str) { | |
var words = str.split(" "); | |
str = ""; | |
for(var i = 0; i < words.length; i++){ | |
if(words[i].length > str.length){ | |
str = words[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 titleCase(str) { | |
var words = str.split(" "); | |
for(var i = 0; i < words.length; i++){ | |
var temp = words[i].split(""); | |
for(var j = 0; j < temp.length; j++){ | |
if(j === 0){ | |
temp[j] = temp[j].toUpperCase(); |
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 temp = []; | |
for(var i = 0; i < arr.length; i++){ | |
var elem = arr[i]; | |
elem.sort(function(a, b){ | |
return a < b; | |
}); | |
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 substrStart = str.length - target.length; | |
if(str.substr(substrStart, str.length) === target){ | |
return true; | |
} else{ | |
return false; | |
} | |
return str; | |
} |
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){ | |
if(str.length > num){ | |
str = str.slice(0, num - 3); | |
str += "..."; | |
} | |
} else{ | |
str = str.slice(0, num); | |
str += "..."; |
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 chunkArrayInGroups(arr, size) { | |
var tempArr = []; | |
var innerTempArr = []; | |
for(var i = 0; i < arr.length; i++){ | |
if(innerTempArr.length < size){ | |
innerTempArr.push(arr[i]); | |
} else{ | |
tempArr.push(innerTempArr); | |
innerTempArr = []; | |
innerTempArr.push(arr[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
// Remove all "flasy" values from an Array. | |
// Falsy values in JavaScript are false, null, 0, "", undefined, and NaN. | |
function bouncer(arr) { | |
var test = function(x){ | |
return Boolean(x); | |
}; | |
for(var i = 0; i < arr.length; 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
// Remove elements from an array that match additional parameters passed to function. | |
function destroyer(arr) { | |
var args = Array.from(arguments); | |
return arr.filter(function(x){ | |
return !args.includes(x); | |
}); | |
} |
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
// Searches for index to insert given parameter into array in ascending order. | |
function getIndexToIns(arr, num) { | |
arr.sort(function(x, y){ | |
return x > y; | |
}); | |
for(var i = 0; i < arr.length; i++){ | |
if(num <= arr[i]){ |
OlderNewer