Created
May 22, 2019 15:42
-
-
Save AndrewKiri/adcf4f6eb01ac874f4315b242ee22992 to your computer and use it in GitHub Desktop.
Pavel - live coding
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 inputString = 'cat has eaten big fat nimble fish, which made the cat fat'; | |
const filter = (filterValue, input) => input.split(' ') | |
.reduce((acc, curr) => { | |
if (curr !== filterValue) acc.push(curr); | |
return acc; | |
}, []) // ['has', 'eaten' ...] | |
.join(' ') | |
; | |
filter('cat', inputString); // 'has eaten big fat nimble fish, which made the fat' | |
------------------------------------------------------------------------------------ | |
// do not use % | |
function isEven(num) { | |
let N = Math.abs(num); | |
if (N === 1) { | |
return false; | |
} | |
if (N === 0) { | |
return true; | |
} | |
isEven(N - 2); | |
} | |
isEven(8) // true | |
isEven(-7) // false | |
isEven(13) // false (-13) | |
isEven(1) // false | |
isEven(0) // true | |
isEven(-1) // false | |
isEven(-29) // false | |
------------------------------------------------------------------------------------ | |
function range (from, to, step) { | |
let ourArray = []; | |
for (let i = from; i < (to/step); i + step) { | |
ourArray.push(i + step); | |
} | |
return ourArray; | |
} | |
range(2, 26, 2) // [2, 4, 6, 8 ... 26] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment