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 vowels from the string | |
function disemvowel(str) { | |
return str.replace(/[aeiou]/gi, ''); | |
} | |
console.log(disemvowel("This website is for losers LOL!")); |
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
// Rotate the array (first arg) left n (second arg) amount of times | |
function arrRotate(arr, n) { | |
let i = 0; | |
let result = arr.map(function() { | |
return arr[ (i++ + n) % arr.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
//Compare the values of 2 arrays. | |
//If Alice[i] > Bob[i], then Alice is awarded 1 point. | |
//If Alice[i] < Bob[i] , then Bob is awarded 1 point. | |
//If Alice[i] = Bob[i], then neither person receives a point. | |
function compArr(alice , bob){ | |
alicePoints = 0; | |
bobPoints= 0; | |
for(i=0; i < 3; 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
//Given an array of X integers, can you find the sum of its elements? | |
function sumArr(arr) { | |
let sum = arr.reduce((a,b) => { | |
return a+b; | |
}, 0); | |
return sum; | |
} | |
console.log(sumArr([1,2,3,4,10,11])); | |
console.log(sumArr([2,6,9,15,25,42])); |
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 program that prints the numbers from 1 to 100. But for multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”. For numbers which are multiples of both three and five print “FizzBuzz | |
function fizzBuzz(num) { | |
console.log(num); | |
for (var i = 0; i <= 100; i++) { | |
if (i % 5 === 0 && i % 3 === 0 ) { | |
console.log('fizzbuzz'); | |
} else if (i % 5 === 0) { | |
console.log('buzz'); | |
} else if (i % 3 === 0) { |
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 lowest index at which a value (second argument) should be inserted into an array (first argument) once it has been sorted. The returned value should be a number. | |
function getIndexToIns(arr, num) { | |
arr.sort((a,b)=>{ | |
return a - b; | |
}); | |
for(var i in arr) { | |
if(arr[i] >= num) | |
return parseInt(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 elements from the initial array that are of the same value as these arguments. | |
function destroyer(arr) { | |
let argArr = arr.slice.call(arguments); | |
argArr.splice(0,1); | |
return arr.filter((element) => { | |
return argArr.indexOf(element) === -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
// Remove all falsy values from an array. | |
function bouncer(arr) { | |
return arr.filter(Boolean); | |
} | |
console.log(bouncer([7, "ate", "", false, 9])); | |
console.log(bouncer([1, null, NaN, 2, undefined])); | |
console.log(bouncer(["a", "b", "c"])); | |
console.log(bouncer([false, null, 0, NaN, undefined, ""])); |
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 string in the first element of the array contains all of the letters of the string in the second element of the array. | |
function mutation(arr) { | |
// console.log(arr[1].toLowerCase().split('')) | |
return arr[1].toLowerCase() | |
.split('') | |
.every((letter) => { | |
// console.log(arr[0].toLowerCase().indexOf(letter)); | |
return arr[0].toLowerCase() | |
.indexOf(letter) != -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 the remaining elements of an array after chopping off n elements from the head. | |
// The head means the beginning of the array, or the zeroth index. | |
// (non-mutative) | |
function slasher(arr, howMany) { | |
return arr.slice(howMany); | |
} |