You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
25 lines
467 B
25 lines
467 B
// simple recursive counting function
|
|
const counter = (i, upto) => {
|
|
if(i < upto) {
|
|
console.log("counter", i, upto);
|
|
counter(i+1, upto);
|
|
}
|
|
}
|
|
|
|
// use counter to just print out 1-5
|
|
counter(1, 5);
|
|
|
|
// a more complex counter that can call a callback
|
|
const cb_counter = (i, upto, cb) => {
|
|
if(i < upto) {
|
|
cb(i, upto);
|
|
cb_counter(i+1, upto, cb);
|
|
}
|
|
}
|
|
|
|
// do the same thing but with a callback
|
|
cb_counter(1, 6, (i, j) => {
|
|
console.log(i, j)
|
|
});
|
|
|
|
|
|
|