1
\$\begingroup\$

The task:

Given a real number n, find the square root of n. For example, given n = 9, return 3.

My solution:

const findRoot = n => n >=  0 ? n ** .5 : void 0;

console.log(findRoot(9));

Is this some kind of trick question? What's there to solve? Did I miss something?

\$\endgroup\$
  • 2
    \$\begingroup\$ -1 is a real number. You might also be meant to solve it without using sqrt or floating-point exponentiation. \$\endgroup\$ – Oh My Goodness Mar 30 at 0:27
  • \$\begingroup\$ It’s a binary search question. \$\endgroup\$ – E.Coms Apr 2 at 1:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.