Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function asyncAddOne(x, callBack) {
- setTimeout(function() {
- return callBack(x + 1);
- }, 200);
- }
- function asyncDouble(x, callBack) {
- setTimeout(function() {
- return callBack(x * 2);
- }, 200);
- }
- function asyncTimesTen(x, callBack) {
- setTimeout(function() {
- return callBack(x * 10);
- }, 200);
- }
- // Create this function!
- function waterfall(arg, tasks, cb) {
- let count = 0;
- let x = arg;
- if(count < tasks.length) {
- tasks[count](x, function (x) {
- count++;
- tasks[count] (x, function(x) {
- count++;
- tasks[count] (x, function(x) {
- count++;
- cb(x);
- });
- });
- });
- };
- }
- waterfall(3, [asyncAddOne, asyncDouble, asyncTimesTen], function(result) {
- console.log('Test 1');
- if (result !== 80) {
- console.log('test failed, expected 80 but got', result);
- } else {
- console.log('Test 1 passed!');
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement