Skip to content

Commit

Permalink
Merge pull request #811 from null-a/repeat-arg-check
Browse files Browse the repository at this point in the history
Add argument checks to repeat function
  • Loading branch information
stuhlmueller committed Apr 7, 2017
2 parents afeae3e + 94c06e3 commit ab39ab5
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/header.wppl
Original file line number Diff line number Diff line change
Expand Up @@ -384,17 +384,22 @@ var groupBy = function(cmp, ar) {

var repeat = function(n, fn) {
var helper = function(m) {
if (m == 0) {
if (m === 0) {
return [];
} else if (m == 1) {
} else if (m === 1) {
return [fn()];
} else {
var m1 = Math.ceil(m / 2),
m2 = m - m1;
return helper(m1).concat(helper(m2));
}
}

if (!util.isInteger(n) || n < 0) {
error('Expected first argument to be a non-negative integer.');
}
if (!_.isFunction(fn)) {
error('Expected second argument to be a function.');
}
return helper(n);
}

Expand Down

0 comments on commit ab39ab5

Please sign in to comment.