-
Notifications
You must be signed in to change notification settings - Fork 0
range
김태헌 edited this page Sep 26, 2024
·
3 revisions
import { range } from 'mori-ts';
const numbers = [...range(5)];
console.log(numbers); // [0, 1, 2, 3, 4]
import { range } from 'mori-ts';
const numbers = [...range(2, 5)];
console.log(numbers); // [2, 3, 4]
import { range } from 'mori-ts';
const numbers = [...range(2, 10, 2)];
console.log(numbers); // [2, 4, 6, 8]
import { range } from 'mori-ts';
const numbers = [...range(5, 0, -1)];
console.log(numbers); // [5, 4, 3, 2, 1]
const numbersWithStep = [...range(5, 0, -2)];
console.log(numbersWithStep); // [5, 3, 1]
import { pipe, map, toArray } from 'mori-ts';
const result = pipe(range(5), toArray);
console.log(result); // [0, 1, 2, 3, 4]
const resultWithStep = pipe(range(5, 10), toArray);
console.log(resultWithStep); // [5, 6, 7, 8, 9]
const resultWithStepTwo = pipe(range(5, 10, 2), toArray);
console.log(resultWithStepTwo); // [5, 7, 9]
const resultMapped = pipe(
range(5),
map(x => x * 2),
take(3),
toArray,
); // 출력: [0, 2, 4]
const resultReduced = pipe(
range(0, 10),
map(x => x * 2),
filter(x => x % 2 === 0),
reduce((acc, x) => acc + x),
); // 출력: 90
https://github.com/gangnamssal/mori-ts/blob/main/src/test/range.spec.ts