Nice work!
Here's feedback I might share during a team code review. Just some things to think about?
number
may not be the best name for a variable? Start thinking about descriptive names.
True, it is a number. But in your logic what does it represent? Maybe it's a potentialSquare
or operand
?
Also, what does the variable i
represent? In looping code, it's usually the counter. But in your case, it's the potentialRoot
. This makes the next question a little easier to ask, and understand.
If the square of the potentialRoot
is greater than your operand
, do you still need to loop through the remaining potentialRoots? That is, if your operand is 18, and your potentialRoot
is 5, so 5 x 5 = 25, you know that's not a root, and you ALSO know anything past 5 won't be roots either.
Final thought. Your function is nicely named rootFinder()
. But you do not return a root! Instead you return a String
. Another team code review comment, consider returning an Int
, instead of a String. If the function throws, you know there's no root, but if it returns an Int
, voila! Root found.
Final team review comment. Your last line is not a root, nor is it an error. Consider adding a new value to your Error enumeration
. If you get to an unknown state, throw that error, instead of the Help text.
Keep coding!