Skip to content

A JS library to remove boilerplate from for-loops.

Notifications You must be signed in to change notification settings

ItsAnoch/repeatjs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 

Repository files navigation

RepeatJS

JS Library to remove boiler-plate from loops.

Exact same speed as a normal for-loop.


Installation

npm install repeatjs

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)

About

A JS library to remove boilerplate from for-loops.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published