code.ashish.me

Atom feed

Recently added: 128 Longest Consecutive Sequence, 347 Top K Frequent Elements, 045 Jump Game 2, 228 Summary Ranges, 219 Contains Duplicate 2

02 Check Armstrong Number

function checkArmstrong(num) {
  const digits = num.toString().split('')
  let sum = 0
  digits.forEach(value => {
    sum += value ** digits.length
  })
  return sum === num
}

console.log(checkArmstrong(153))

Created 2019-11-24T04:53:20+05:30 · Edit