백준 11720 : 숫자의 합 nodejs 풀이

김김김·2022년 3월 31일
0

알고리즘 노트

목록 보기
5/16

문제 링크 여기로!

다음과 같이 풀었다.

const fs = require("fs");
const input = fs.readFileSync("/dev/stdin").toString().split("\n");

console.log(
  input[1].split("").reduce((acc, cur) => {
    return acc + Number(cur);
  }, 0)
);

오늘의 수확 : 숫자로 이루어진 문자데이터 앞에 부호를 붙이면(+cur처럼) Number 형변환 효과를 낸다는 것을 알게 되었다.

profile
블로그 이전했습니다. https://sadie100.tistory.com/

0개의 댓글

관련 채용 정보

Powered by GraphCDN, the GraphQL CDN