Skip to content
김태헌 edited this page Sep 26, 2024 · 4 revisions

예시 1: 기본 사용법

import { reduce } from 'mori-ts';

const numbers = [1, 2, 3, 4, 5];
const result = reduce((acc, value) => acc + value, 0, numbers);

console.log(result); // 15

예시 2: 객체와 함께 사용하기

import { reduce } from 'mori-ts';

const objects = [{ x: 1 }, { x: 2 }, { x: 3 }, { x: 4 }, { x: 5 }];
const result = reduce((acc, value) => acc + value.x, 0, objects);

console.log(result); // 15

예시 3: 파이프라인과 함께 사용하기

import { reduce, pipe, toAsync } from 'mori-ts';

const iter = [1, 2, 3];

const res = pipe(
  iter,
  toAsync,
  reduce((acc, value) => acc + value),
); // 출력: 6

테스트 코드 링크

https://github.com/gangnamssal/mori-ts/blob/main/src/test/reduce.spec.ts

Clone this wiki locally