Skip to content

Commit

Permalink
Merge pull request #4 from bunnydeviloper/problem5
Browse files Browse the repository at this point in the history
solved #5: call f(x) multiple times
  • Loading branch information
bunnydeviloper authored Oct 19, 2017
2 parents 8475bc4 + 6b9dfca commit a9c253a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
8 changes: 8 additions & 0 deletions solutions/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const callX = (fun, n) => {
if (n > 0) {
fun();
callX(fun, n-1);
}
};
module.exports = callX;

18 changes: 18 additions & 0 deletions test/5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const callX = require('../solutions/5.js');

const test = (callTotal, callTest) => {
let i = 0;
const fun = () => {
i++;
};
callX(fun, callTotal);
if (i === callTest) {
console.log(`Function sucessfully repeated ${i} times.`);
} else {
console.log('Check your code again!');
}
};

test(4,7);
test(10,10);
test(-1,1);

0 comments on commit a9c253a

Please sign in to comment.