General limitations
- Read this first http://eloquentjavascript.net/05_higher_order.html
- You are not allowed to change input variable of a any function.
- You are allowed to use only 'const' for declaring variables and functions.
- You are not allowed to use any of ++ or -- operators.
- You are not allowed to use 'delete' operator
- You are not allowed to use .shift, .splice, .push or any function that mutates an array in place.
- You cannot mutate and created object. example: const a = {key: 1}; a.key = 123
- First write without limitations, then refactor code to match limitations
1. Write a function that accepts another function as an argument and call that function passing a number
const giveRand = callback => {
callback(Math.random())
}
Write a function that calls function 'giveRand' 10 times and averages the results.
const f = (argument, callback) => {
if (argument === 4) {
callback(false)
return
}
callback(true)
}
const array = [2, 3, 4, 5, 6, 7, 8]
Write a function that calls function 'f' for each element of an array, starting from the first one, and if callback receives 'true', stop calling 'f'
const giveTrueIf4Async = (arg, callback) => {
const result = arg === 4
const f = () => callback(result)
setTimeout(f, 10)
}
const array = [2, 3, 4, 5, 6, 7, 8]
Write a function that calls function 'giveTrueIf4Async' for each element of an array, one at a time, starting from the first one, and if callback receives 'true', stop calling 'giveTrueIf4Async'
const giveRandAsync = callback => {
const f = () => callback(Math.random())
setTimeout(f, 10)
}
- Call function 'giveRandAsync' 10 times and gather results in an array
- Call function 'giveRandAsync' 10 times, one at a time, and average the results
- Call function 'giveRandAsync' 10 times, one at a time with 20 second interval, and average the results
- Call function 'giveRandAsync' 10 times, all at once, and average the results
Array.push is allowed here
Write your own implementation of async.waterfall function Write your own implementation of async.parallel function
- Write your own implementation of bluebird's functions.
- Promise.map
- Promise.all
- Promise.each
- Promise.tap
- Promise.thenReturn