That's one way to do it
-
With big number (I mean really big numbers), you will run into a StackOverflowException. What about "tail recursion"? :-D
Oh sanctissimi Wilhelmus, Theodorus, et Fredericus!
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
100% this is a joke, and I like it.
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
At first I thought "Dang! I am looking for a package that determines if a number is odd." But it actually turns out that they have helpfully written one. Here it is if anyone else needs it -> odd numbers[^] A real godsend!
βThat which can be asserted without evidence, can be dismissed without evidence.β
β Christopher Hitchens
-
Me: Have Security dress the guy in a hazmat suit, and escort him out of the building. I'd then cordon off the area and decontaminate everything he touched on his visit - in an autoclave, by choice. This level of stupidity leaves traces wherever it goes.
Freedom is the freedom to say that two plus two make four. If that is granted, all else follows. -- 6079 Smith W.
Daniel Pfeffer wrote:
I'd then cordon off the area and decontaminate everything he touched on his visit - in an autoclave, by choice
Anything wrong with fire?
Wrong is evil and must be defeated. - Jeff Ello
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
Just what I was looking for! My own isEven function only goes to 1000, this is a huge step forward :D Just need to brace it properly and remove all those function exits...
function isEven(number) {
let result;
if (number === 1) {
result = false;
}
else if (number === 2) {
result = true;
}
else if (number === 3) {
result = false;
}
// ...
return result;
}And they have an is-odd package which is consistent with this one too. As programmers we know how important it is to be consistent. Thanks for this great find! :thumbsup: :-D
Best, Sander Azure DevOps Succinctly (free eBook) Azure Serverless Succinctly (free eBook) Migrating Apps to the Cloud with Azure arrgh.js - Bringing LINQ to JavaScript
-
That can be done better with a recursive function:
function IsEven(number) {
if (number === 1 return false;
elseif (number === 2) return true;
else return IsEven(number - 2);
}Now it does all positive numbers :laugh: EDIT: because I get serious reactions on this code The code above is how NOT to do it - it's satire.
hope your happy!!
-
Well, if you troll, then you might just as well do it right, walking the walk way to the end.
..lead the way please.. ..you will be lost first.. π€©π€©π€©π€©
-
..yes..is there anything else i should be serious about?.. π€ͺπ€ͺπ€ͺπ€ͺ
-
Now the question is... Is the one with that request trolling him? Or does he really needs it for his usage?
M.D.V. ;) If something has a solution... Why do we have to worry about?. If it has no solution... For what reason do we have to worry about? Help me to understand what I'm saying, and I'll explain it better to you Rating helpful answers is nice, but saying thanks can be even nicer.
..got it perfectly..but are we on the same page? really?.. ππππ
-
Daniel Pfeffer wrote:
I'd then cordon off the area and decontaminate everything he touched on his visit - in an autoclave, by choice
Anything wrong with fire?
Wrong is evil and must be defeated. - Jeff Ello
..better be ready..you cant fight fire with fire.. ..you might be burned.. ..were you?.. π€ π€ π€ π€
-
..lead the way please.. ..you will be lost first.. π€©π€©π€©π€©
That reminds me on that Simpsons episode. The boys hop into the caravan to steal back the lemon tree stolen by Shelbyvillians. After running through Shelbyville for basically ever, someone asks Homer, where he leads them. "I was following Flanders".
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
-
It's at 94.8MB now
Don't waste my time, hahaha! :laugh:
-
I... what?! I thought you were joking for a second but there actually is a definition for even and odd in generic bases. In even bases it's the last-digit test - odd is odd, even is even; in odd bases it's a test of the sum of all digits - odd is odd, even is even. That makes complete sense; it's just not something I've ever considered :omg:
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
They could even have used a switch statement. Odd that they didn't think of that :)
Check out my blog at http://msdev.pro/
-
GitHub - samuelmarina/is-even[^]
Quote:
This is a 100% serious project, and it is made to help the community.
A brief excerpt:
function isEven(number) {
if(number === 1) return false;
else if(number === 2) return true;
else if(number === 3) return false;
else if(number === 4) return true;
else if(number === 5) return false;
else if(number === 6) return true;
else if(number === 7) return false;They're up to 1,000,001 now. Help them grow! :doh:
TTFN - Kent
I feel the power of Javascript infusing me! :laugh:
A new .NET Serializer All in one Menu-Ribbon Bar Taking over the world since 1371!
-
Only works with base-10 ? :-D Surely it would be better written recursively.
PIEBALDconsult wrote:
Only works with base-10 ?
You just need to add conversion functions and call them first.
function hexToDec(number) {
if (number === 1) return 1;
else if (number === 2) return 2;
//...
else if (number === A) return 10;
else if (number === B) return 11;
//...
}Did you ever see history portrayed as an old man with a wise brow and pulseless heart, weighing all things in the balance of reason? Is not rather the genius of history like an eternal, imploring maiden, full of fire, with a burning heart and flaming soul, humanly warm and humanly beautiful? --Zachris Topelius