Created
August 27, 2016 06:41
-
-
Save erdaldalkiran/d7afb6f8d133f9cbbd2ace3787760514 to your computer and use it in GitHub Desktop.
Bahmutov - Essence of functional programming
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
//----------------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