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
const maxMultiple = (divisor, bound) => { | |
let result = divisor; | |
for (let i = divisor; i <= bound; i *= divisor) { | |
result = i; | |
} | |
return result; | |
} |
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
const largestNumber = num => { | |
result = ''; | |
for(let i = 1; i <= num; i++) { | |
result += '9'; | |
} | |
return parseInt(result); | |
}; |
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
const firstDigit = str => str.split('').filter(s =>!isNaN(s))[0]; | |
describe('firstDigit()', () => { | |
it('return the first digit in a string', () => { | |
// arrange | |
const str = "var_1__Int2"; | |
// act | |
const result = firstDigit(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
// basic with for loop | |
const factorialNumber = num => { | |
let result = 1; | |
for(let i = result + 1; i <= num; i++) { | |
result *= i; | |
} | |
return result; | |
}; |
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
const encloseInBrackets = str => `(${str})`; | |
describe('encloseInBrackets()', () => { | |
it('adds () around a string', () => { | |
// arrange | |
const str = "Yo"; | |
// act | |
const result = encloseInBrackets(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
const caseInsensitivePalindrome = str => str.toLowerCase() === str.split('').reverse().join('').toLowerCase(); | |
describe('caseInsensitivePalindrome()', () => { | |
it('returns true for a case insensitive palindrome', () => { | |
// arrange | |
const str = 'AaBaa'; | |
// act | |
const result = caseInsensitivePalindrome(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
const arrayReplace = (array, elemToReplace, substitutionElem) => array.map((el, i) => el === elemToReplace ? substitutionElem : el); | |
describe('arrayReplace()', () => { | |
it('adds a border around entire application', () => { | |
// arrange | |
const array = [1, 2, 1]; | |
const elemToReplace = 1; | |
const substitutionElem = 3; | |
// act |
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
const alternatingSums = weights => [ | |
weights.filter((weight, i) => i % 2 === 0).reduce((a, c) => a + c), | |
weights.filter((weight, i) => i % 2 !== 0).reduce((a, c) => a + c) | |
]; | |
describe('alternatingSums()', () => { | |
it('returns alternating sums of even and odd', () => { | |
// arrange | |
const nums = [50, 60, 60, 45, 70]; |
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
const allLongestStrings = array => { | |
let longestLength = array[0].length; | |
array.forEach(s => { | |
longestLength = s.length > longestLength ? s.length : longestLength; | |
}); | |
return array.filter(s => s.length === longestLength); | |
} | |
/** |
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
const add = (...nums) => nums.reduce((a, c) => a + c); | |
describe('add()', () => { | |
it('adds two numbers', () => { | |
// arrange | |
const num1 = 1; | |
const num2 = 2; | |
// act | |
const result = add(num1, num2); |
NewerOlder