JavaScript's Modulo
Introduction
Hey what's up people since I signed up here, I would like to share this kinda tip about a mathematic this called "modulo". Which is the remainder of division using the % symbol, known as the modulus operator.
Example
And it could be used in the following function for example:
Use the
var isOdd = function (n) {
if (n % 2 === 0) {
return false;
} else {
return true;
}
};
.
Written by Bilal Ketab
Related protips
2 Responses
var isOdd = function (n) { return !!(n % 2); };
I think it's easier :)
over 1 year ago
·
@avenger7x just saying ;)
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Javascript
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#