Answer the question
In order to leave comments, you need to log in
Why is parity minus one not defined?
habrahabr.ru/post/240349 - in this article on Habré there is a task of writing a recursive function that returns the parity of a number ..
The code actually from their example is this
function isEven(n) {
if (n == 0)
return true;
else if (n == 1)
return false;
else if (n < 0)
return isEven(-n);
else
return isEven(n - 2);
}
Answer the question
In order to leave comments, you need to log in
The code looks correct. How was the work checked?
function isEven(n) {
if (n == 0)
return true;
else if (n == 1)
return false;
else if (n < 0)
return isEven(-n);
else
return isEven(n - 2);
}
alert( isEven('-1') )ж
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question