-
Notifications
You must be signed in to change notification settings - Fork 0
compact
김태헌 edited this page Sep 26, 2024
·
3 revisions
import { compact } from 'mori-ts';
const arr = [1, 2, 3, 0, null, undefined, false, 5];
const result = [...compact(arr)];
console.log(result); // 출력: [1, 2, 3, 5]
import { compact, toArray } from 'mori-ts';
const asyncIterable = (async function* () {
yield 1;
yield null;
yield 2;
yield undefined;
yield 3;
yield false;
})();
const result = await toArray(compact(asyncIterable));
console.log(result); // 출력: [1, 2, 3]
import { pipe, range, map, compact, toArray } from 'mori-ts';
const res = pipe(
range(1, 10),
map(n => (n % 2 === 0 ? 0 : n)),
compact,
toArray,
);
console.log(res); // 출력: [1, 3, 5, 7, 9]
https://github.com/gangnamssal/mori-ts/blob/main/src/test/compact.spec.ts