UNPKG

number-theory

Version:

Number theory functions for javascript.

18 lines (15 loc) 510 B
'use strict'; /** * Determines whether an integer is 'octagonal'. * Algorithm works by finding the 'octagonal root' of an int, * then checking to see whether the result's a whole number. * See: https://en.wikipedia.org/wiki/Octagonal_number * * @param {Number} an integer x to test * @return {Boolean} Whether or not the x is octagonal. * @module number-theory * @author Kelly Innes */ module.exports = function isOctagonal(n) { return (((Math.sqrt((3 * n) + 1)) + 1) / 3) % 1 == 0; };