[프로그래머스]연습문제 - 하샤드 수

·2021년 10월 29일
0

코테문제풀기

목록 보기
24/57

문제확인

https://programmers.co.kr/learn/courses/30/lessons/12947

문제풀이

function solution(x) {
  var answer = true;
  const arr = [];
  let n = x;
    
  while(n > 0) {
      arr.push(n % 10);
      n = Math.floor(n / 10);
  }
  
  const sum = arr.reduce((a, b) => a + b);
    
  return x % sum === 0 ? true : false;
}

0개의 댓글