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
// Reverse the provided string. | |
// You may need to turn the string into an array before you can reverse it. | |
// Your result must be a string. | |
function reverseString(str) { | |
var reverseStr = str.split('').reverse().join(''); | |
return reverseStr; |
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
// Return the factorial of the provided integer. | |
// If the integer is represented with the letter n, a factorial is the product of all positive integers less than or equal to n. | |
// Factorials are often represented with the shorthand notation n! | |
// For example: 5! = 1 * 2 * 3 * 4 * 5 = 120 | |
function factorialize(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
// Return true if the given string is a palindrome. Otherwise, return false. | |
function palindrome(str) { | |
var x = str.replace(/[^a-z0-9+]+/gi, '').toLowerCase(); | |
if(x.split('').reverse().join('') === x) { | |
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
// Return the length of the longest word in the provided sentence. | |
// Your response should be a number. | |
function findLongestWord(str) { | |
var longestWord = str.split(' ').reduce(function(longest, currentWord) { | |
return currentWord.length > longest.length ? currentWord : longest; | |
}, ""); | |
return longestWord.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
// Return the provided string with the first letter of each word capitalized. Make sure the rest of the word is in lower case. | |
// For the purpose of this exercise, you should also capitalize connecting words like "the" and "of". | |
function titleCase(str) { | |
str = str.toLowerCase().split(' '); | |
for(var i=0; i < str.length; i++) { | |
str[i]= str[i].charAt(0).toUpperCase() + str[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
// Return an array consisting of the largest number from each provided sub-array. For simplicity, the provided array will contain 4 sub-arrays. | |
function largestOfFour(arr) { | |
let largestNumber = [0,0,0,0]; | |
for(var i=0; i < arr.length; i++) { | |
for(var j=0; j < arr[i].length; j++) { | |
if(arr[i][j] > largestNumber[i]) { | |
largestNumber[i] = arr[i][j]; | |
} | |
} |
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
// Check if a string (first argument, str) ends with the given target string (second argument, target). | |
function confirmEnding(str, target) { | |
return str.substr(-target.length) === target; | |
} | |
console.log(confirmEnding("Bastian", "n")); | |
console.log(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
// Repeat a given string (first argument) num times (second argument). Return an empty string if num is not a positive number. | |
function repeatStringNumTimes(str, num) { | |
let finalStr = ""; | |
while(0 < num) { | |
finalStr += str; | |
num--; | |
} | |
return finalStr; | |
} |
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 str.length > str.length num | |
// return ... | |
// if the str.length num <= 3 | |
// the dots do Not add to str.length | |
// console.log(str.length); | |
// console.log(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
// 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) { | |
let tempArr = []; | |
let newArr = []; | |
for(i=0; i <arr.length; i++) { | |
if( i % size !== size-1) | |
tempArr.push(arr[i]); |
OlderNewer