본문 바로가기

nodejs

또 사용할것 같은 custom 함수들

- chunk array

function chunk(array: object[], size: number) {
  const chunked: object[] = [];
  let index = 0;

  while (index < array.length) {
    chunked.push(array.slice(index, index + size));
    index += size;
  }

  return chunked;
}

 

- sleep

function sleep(ms: number) {
  return new Promise((resolve) => setTimeout(resolve, ms));
}
반응형

'nodejs' 카테고리의 다른 글

redis connect  (0) 2022.06.09
typescript 꿀팁  (0) 2022.03.03
typeorm repository 뿌수기  (0) 2022.02.15
aws s3 endpoint 적용기  (0) 2022.02.04
typeorm multiple database  (0) 2021.08.03