This file contains hidden or 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
| const reverseString = (originalString) => { | |
| return originalString.split('').reverse().join(''); | |
| } |
This file contains hidden or 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
| const recursiveReverseString = (originalString) => { | |
| let reversedString = ''; | |
| let formReverseString = (word) => { | |
| if(word.length > 0) { | |
| reversedString = formReverseString(word.substr(1)) + word.charAt(0); | |
| return reversedString; | |
| } | |
| return ''; | |
| } | |
| formReverseString(originalString); |
This file contains hidden or 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
| const recursiveReverseString = (originalString) => { | |
| return originalString ? recursiveReverseString(originalString.substr(1)) + originalString.charAt(0): ''; | |
| } | |
| let r = recursiveReverseString('hello'); | |
| console.log(r); |
This file contains hidden or 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
| const recursiveMultiplier = (arr, num) => { | |
| let newArray = []; | |
| let mult = function(a) { | |
| if(a.length) { | |
| newArray[a.length-1] = a.pop()*num; | |
| mult(a); | |
| return newArray; | |
| } | |
| return; | |
| } |
This file contains hidden or 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
| const recursiveMultiplier = (arr, num) { | |
| if(!arr.length) { | |
| return arr; | |
| } | |
| let lastElement = arr.pop(); | |
| recursiveMultiplier(arr, num); | |
| arr.push(lastElement*num); | |
| return arr; |
This file contains hidden or 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
| const recursiveCountDown = (n) => { | |
| if(n < 0){ | |
| return; | |
| } | |
| x = n - 1; | |
| return recursiveCountDown(x); | |
| } | |
| recursiveCountDown(10); |
This file contains hidden or 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
| const recursiveExponent = (base, exponent) => { | |
| return exponent === 1? base: base*recursiveExponent(base, exponent-1); | |
| } | |
| const y = recursiveExponent(2,5); | |
| console.log(y); |
This file contains hidden or 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
| const reverse = (x) => { | |
| if(x === ''){ | |
| return ''; | |
| } else if(x%10 === 0) { | |
| x = parseInt(x/10); | |
| return reverse(x); | |
| } else if(x < 0) { | |
| x = -x; | |
| return reverse(x)*(-1); | |
| } else { |
This file contains hidden or 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
| const sumDigits = (x) => { | |
| if(x === '') { | |
| return 0; | |
| } else if(x < 10) { | |
| return x; | |
| } else { | |
| let newX = x + ''; | |
| newX = newX.split(''); | |
| let sumX = parseInt(newX.pop()) + sumDigits(parseInt(newX.join(''))); | |
| return sumX < 10 ? sumX : sumX%10 + Math.floor(sumX/10); |
This file contains hidden or 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
| const isPowerOfThree = (num) => { | |
| if(num === 1) { | |
| return true; | |
| } else if(num > 1 && num%3 === 0) { | |
| return isPowerOfThree(num/3); | |
| } else { | |
| return false; | |
| } | |
| } |
OlderNewer