UNPKG

mathball

Version:

A JavaScript library for Competitive Programming

15 lines (12 loc) 345 B
'use strict'; /* Armstrong Number * Function: isArmstrong() */ var validate = require('../validation/positive-integer'); exports.check = function (num) { validate(num, 'isArmstrong'); var str = num.toString(); return num == str.split('').reduce(function (prev, next) { return prev + Math.pow(parseInt(next, 10), str.length); }, 0); };