GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • LeetCodeJavascript.com
  • Star on GitHub

This view

  • Original page
  • New address

GeezerVison is showing leetcodejavascript.com — #1134 - Armstrong Number - LeetCode JavaScript Solutions

Back to all solutions

#1134 - Armstrong Number

Easy • View on LeetCode • View on GitHub
Math

Problem Description

Given an integer n, return true if and only if it is an Armstrong number.

The k-digit number n is an Armstrong number if and only if the kth power of each digit sums to n.

Solution

/**
 * @param {number} n
 * @return {boolean}
 */
var isArmstrong = function(n) {
  const digits = n.toString();
  const digitCount = digits.length;
  const digitSum = digits
    .split('')
    .reduce((sum, digit) => sum + Math.pow(parseInt(digit, 10), digitCount), 0);

  return digitSum === n;
};
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.