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 factorialize(num) { | |
if (num === 0) { | |
return 1; | |
} else { | |
for (var i = num; i > 1; i--) { | |
num *= (i-1); | |
} | |
return num; | |
} | |
} |
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 reverseString(str) { | |
str = str.split('').reverse().join(''); | |
return str; | |
} | |
reverseString('hello'); |
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; |
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) { | |
str = str.split(' '); | |
var longestWord = ''; | |
console.log(str); | |
for (var i in str) { | |
if (str[i].length >= longestWord.length) { | |
longestWord = str[i]; | |
console.log(longestWord); | |
} | |
} |
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) { | |
var rp = /[\s\W]*/; //remove punctuation | |
var checkPalindrome = str.toLowerCase().split(rp).reverse().join(''); | |
console.log(checkPalindrome); | |
if (checkPalindrome === str.toLowerCase().split(rp).join('')) { | |
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 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 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 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); |
OlderNewer