Bahmutov - Essence of functional programming
//----------------first | |
// function timedPrint(character, N, interval) { | |
// var counter = 0; | |
// var intervalId = setInterval(function () { | |
// console.log(character); | |
// counter += 1; | |
// if (counter >= N) { | |
// clearInterval(intervalId); | |
// console.log('done printing', character, N, 'times'); | |
// } | |
// }, interval); | |
// } | |
// timedPrint('a', 3, 1000); | |
//----------------second | |
// const printA = console.log.bind(console, 'a'); | |
// const timedPrint = (workload, N, interval) => { | |
// let counter = 0; | |
// const intervalId = setInterval(function(){ | |
// workload(); | |
// counter++; | |
// if(counter === N){ | |
// console.log('printing is done'); | |
// clearInterval(intervalId); | |
// } | |
// }, interval); | |
// } | |
// timedPrint(printA, 3, 1000); | |
//----------------third | |
const printCharacter = (c) => console.log(c); | |
const countToN = (n) => { | |
let start = 0; | |
return () =>{ | |
start++; | |
return start === n; | |
}; | |
}; | |
const timedPrint = (workload, isDone, interval) => { | |
const intervalId = setInterval(function(){ | |
workload(); | |
if(isDone()){ | |
console.log('printing is done'); | |
clearInterval(intervalId); | |
} | |
}, interval); | |
} | |
timedPrint(printCharacter('a'), countToN(3), 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment