Skip to content

Instantly share code, notes, and snippets.

View DazzGranto's full-sized avatar
💙
run

Dazz Granto DazzGranto

💙
run
  • will be one day
  • TTTTTTTTTTTTTTTTTTTTTTTTTTT
View GitHub Profile
@DazzGranto
DazzGranto / range.js
Last active May 29, 2024 01:31
Range in JavaScript (Sequence generator)
// Sequence generator function (commonly referred to as "range", e.g. Clojure, PHP etc)
const range = (start, stop, step = 1) => Array.from({ length: (stop - start) / step + 1}, (_, i) => start + (i * step));
// Generate numbers range 0..4
range(0, 4);
// [0, 1, 2, 3, 4]
// Generate numbers range 1..10 with step of 2
range(1, 10, 2);
// [1, 3, 5, 7, 9]