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

예시 1: 문자열의 길이 구하기

import { length } from 'mori-ts';

const str = "Hello, Mori!";

const result = length(str);

console.log(result); // 출력: 12

예시 2: 배열의 길이 구하기

import { length } from 'mori-ts';

const arr = [1, 2, 3, 4, 5];

const result = length(arr);

console.log(result); // 출력: 5

예시 3: 비어 있는 배열의 길이

import { length } from 'mori-ts';

const emptyArr = [];

const result = length(emptyArr);

console.log(result); // 출력: 0

예시 4: 파이프라인과 함께 사용

import { pipe, range, length } from 'mori-ts';

const res = pipe(range(1, 10), length);
console.log(res); // 출력: 9

const res2 = pipe(range(1, 5), toAsync, length);
res2.then(console.log); // 출력: 4

테스트 코드 링크

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

Clone this wiki locally