2.0.0 • Published 8 years ago
loop-for-n-times v2.0.0
Summary
A looping construct for people who don't like the word "for".
Description
loop-for-n-times
defines a function with the following parameters:
initial-value
(Any): any value that you like, used to set the initial value of the looping counter.compare
(Function): a function that receives the current value of the looping counter and returns a Boolean true or false as it so to either continue or stop looping.increment
(Function): a function that receives the current value of the looping counter and returns the next value of the looping counter.body
(Function): a function that receives the current value of the looping counter and does whatever it wants with is.
Example:
var loop = require('loop-for-n-times'),
n = 0;
loop(
_ => 0,
i => i < 10,
i => i + 1,
i => n += i);
console.log("n is 45: %s", n === 45);