1.0.3 • Published 2 years ago

repeatjs v1.0.3

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

RepeatJS

JS Library to remove boiler-plate from loops.

Exact same speed as a normal for-loop.


Installation

npm install repeatjs

Importing

import repeat from "repeatjs/index.js";

Syntax:

repeat((index, end) => { // Index and end can be renamed to anything.
    // code here
}, iterations, step, start)

Example Code

Output numbers from 0 to 10

repeat((index) => {
    console.log(index)
}, 10)

Output numbers from 5 to 20

repeat((index) => {
    console.log(index)
}, 20, 1, 5) // 20 is the iterations, 1 is the step, and 5 is the starting.

Output even numbers from 10 to 20

repeat((index) => {
    console.log(index)
}, 20, 2, 10) // 20 is the iterations, 2 is the step, and 5 is the starting.

If the index is equal to a random number then break the loop.

const number = Math.floor(Math.random() * 20)

repeat((index, end) => { if (index == number) { end() // end() is equivalent to break; however end() can be used in functions unlike break; } console.log(index) }, 20)