Skip to content

Instantly share code, notes, and snippets.

@0Prime
0Prime / Generate Random Number
Created December 9, 2017 23:41 — forked from Nicknyr/Generate Random Number
Javascript: Generate random number and push it to an array
// Generates and logs a random number between 1 and 4, pushes it to an array, and logs it
var arr = [];
function randomNumber() {
var num = Math.floor((Math.random() * 4) + 1);
arr.push(num);
console.log(arr);
}
@0Prime
0Prime / Call function synchronously while iterating through array elements Javascript: Looping over an array and calling a function in a sychronous manner using setInterval
/**
* At specified interval takes next x of xs and calls f(x)
* Returns abort function, which stops iteration
* @param xs - arguments array for f
* @param f - a function
* @param delay - delay between calls, ms
*/
const intervalForEach = (xs, f, delay) => {
const gen = xs.entries()
const id = setInterval(() => {