mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-05 16:26:47 +08:00

* Make `PerfectCube` more correct and readable * Add negative and Infinity tests * Fixed comment formatting * Realized BigInt support is unnecessary The algorithm would be exactly the same, so there's no added educational value * Update PerfectCube.js * Remove space * Update PerfectCube.js Now `isInt` is replaced by `isFinite`, because `isInt` is a redundant check * Update PerfectCube.js Remove dot * Parity between `PerfectSquare` and `PerfectCube` * Update PerfectSquare.test.js Fixed the old copy-paste error that said "cube" instead of "square". And added `Infinity` test
11 lines
281 B
JavaScript
11 lines
281 B
JavaScript
/**
|
|
* Author: dephraiim
|
|
* License: GPL-3.0 or later
|
|
*
|
|
* This uses `round` instead of `floor` or `trunc`, to guard against potential `cbrt` accuracy errors
|
|
*/
|
|
|
|
const perfectCube = (num) => Number.isFinite(num) && Math.round(Math.cbrt(num)) ** 3 === num
|
|
|
|
export { perfectCube }
|