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 factorialize(num) { | |
var product = 1; | |
for(i = 1;i<=num;i++) | |
{ | |
product = product * i; | |
} | |
return product; |
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) { | |
function reverseString(str) { | |
str = ((str.split('')).reverse()).join(''); | |
return str; | |
} | |
if((str.toLowerCase()).replace(/[\W_]/g,'') === |
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 charCount = 0; | |
var strArray = str.split(' '); | |
for(var i = 0;i < strArray.length ;i++) | |
{ | |
if(strArray[i].length > charCount) | |
{ | |
charCount = strArray[i].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 titleCase(str) { | |
str = str.toLowerCase(); | |
var strArray = (str.split(' ')); | |
for(var i = 0; i < strArray.length; i++) | |
{ | |
strArray[i] = (strArray[i].charAt(0).toUpperCase()) + (strArray[i].substring(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 largestNumberOfArray(arr) { | |
var resultArray = []; | |
for(var i = 0; i < arr.length; i++) | |
{ | |
resultArray.push(arr[i][0]); | |
for(var ii = 0; ii < arr[i].length; ii++) | |
{ |
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 CompairStrTails(str, target) { | |
if(target.length > str.length) | |
{ | |
target = target.substring(target.length-str.length); | |
} | |
str = str.substring(str.length-target.length); | |
if(target === 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 truncateStr(str, num) { | |
if(str.length > num) | |
{ | |
if(num > 3) | |
{ | |
str = str.slice(0,num-3)+"..."; | |
} | |
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 chunkArray(arr, size) { | |
// creates a matrix of N elements from a single array | |
var resultArray = []; | |
for (var i = 0; i < arr.length; i += size) { | |
resultArray.push(arr.slice(i, i + size)); | |
} | |
return (resultArray); |
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 slashArray(arr, howMany) { | |
//cuts first N elements from array. N === howMany | |
return(arr.slice(howMany)); | |
} | |
slashArray([1, 2, 3], 0); |
OlderNewer