← Back to challenges

Iterated Square Root

JavaScriptHardloopsnumbersmath

Instructions

The iterated square root of a number is the number of times the square root function must be applied to bring the number strictly under 2.

Given an integer, return its iterated square root. Return "invalid" if it is negative.

Examples

iSqrt(1) ➞ 0

iSqrt(2) ➞ 1

iSqrt(7) ➞ 2

iSqrt(27) ➞ 3

iSqrt(256) ➞ 4

iSqrt(-1) ➞ "invalid"

Notes

Idea for iterated square root by Richard Spence.

javascript
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: ES6: Destructuring Objects X