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(/ |[,.]/g, '').toLowerCase(); | |
rts = str.split('').reverse().join(''); | |
if(str === rts) { | |
return true; | |
} else {return false;} | |
} | |
palindrome("eye"); |
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 long = 0; | |
for(x=0; x<str.length; x++) { | |
if(str[x].length > long) { | |
long = str[x].length; | |
} | |
} return long; | |
} |
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().split(" "); | |
var word = []; | |
for(x=0; x<str.length; x++) { | |
var a = str[x].charAt(0).toUpperCase(); | |
var b = str[x].substr(1); | |
word.push(a + b); | |
} | |
str = word.join(' '); |
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 largest = 0; | |
var newArr = []; | |
for(x=0; x<arr.length; x++) { | |
for(y=0; y<arr[x].length; y++){ console.log(arr[x][y]); | |
if(arr[x][y]>largest) { | |
largest = arr[x][y]; | |
} | |
} newArr.push(largest); | |
} 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 end(str, target) { | |
str = str.split(" "); | |
if(str.length > 1) { | |
var length = str.length - 1; | |
var last = str[length]; | |
if(last === 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) { | |
var newStr = ""; | |
var i; | |
for (i = 0; i < num; i++) { | |
newStr += str; | |
} return newStr; | |
} | |
repeat('abc', 3); |
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) { | |
var length = str.length; | |
if(length > num) { | |
str = str.substr(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 chunk(arr, size) { | |
var newArr = []; | |
for(x=0; x<arr.length; x+=size) { | |
var add = arr.slice(x, x+size); | |
newArr.push(add); | |
} | |
return newArr; | |
} | |
chunk(['a', 'b', 'c', 'd'], 2); |
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(arr.length > howMany) { | |
arr = arr.splice(howMany); | |
} else { | |
arr = []; | |
} | |
return arr; | |
} | |
slasher([1, 2, 3], 2); |
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 one = arr[0].toLowerCase(); | |
var two = arr[1].toLowerCase().split(''); | |
for(x=0; x<two.length; x++) { | |
if(one.indexOf(two[x]) === -1) { | |
return false; | |
} | |
} return true; | |
} | |
mutation(['hello', 'hey']); |
OlderNewer