eluvatar, (edited )

The errors are great api.isevenapi.xyz/api/iseven/1.5

~~Sadly it’s not always accurate api.isevenapi.xyz/api/iseven/0~~ Edit: nevermind I’m an idiot

It’s also greatly lacking in number support api.isevenapi.xyz/api/iseven/one

huf,

zero is even, so i dont see how that one’s wrong

eluvatar,

Oh you’re right, I’m not sure what I was Ln thinking

xmunk,

Is even states that it only returns true for even, passing in an odd number is technically unsupported.

megaman,

Funny as hell

morrowind,
@morrowind@lemmy.ml avatar

I resent that there is a ruby developer included in there. isEven is not idiomatic naming. You should be using #even? from the standard library

fckreddit,

Sorry sir, most JS developers don’t use standard library functions. We just use npm packages wherever possible.

jubilationtcornpone,

Only way it could be better is if they threw “AI” in there somewhere.

jol,

With the new AI integration, you can get smart isEven results that return the correct answer 90% of the time and a more creative solution 20% of the time.

rem26_art,
@rem26_art@kbin.social avatar

im glad that people are out there building the web services we truly need.

rikudou, (edited )
@rikudou@lemmings.world avatar

If anyone wants a more efficient local version for php:


<span style="color:#323232;">function isEven(int $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while ($number > 2) {
</span><span style="color:#323232;">        $number -= 2;
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Edit: Now with support for large numbers!


<span style="color:#323232;">function isEven(int|string $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while (bccomp($number, 2) === 1) {
</span><span style="color:#323232;">        $number = bcsub($number, 2);
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    $number = (int) $number;
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Edit 2: someone asked for an ad-supported version, here you go!


<span style="color:#323232;">function isEven(int|string $number): bool
</span><span style="color:#323232;">{
</span><span style="color:#323232;">    ${1} = false;
</span><span style="color:#323232;">    ${2} = true;
</span><span style="color:#323232;">
</span><span style="color:#323232;">    while (bccomp($number, 2) === 1) {
</span><span style="color:#323232;">        error_log('Buy isEvenCoin, the hottest new cryptocurrency!');
</span><span style="color:#323232;">        $number = bcsub($number, 2);
</span><span style="color:#323232;">    }
</span><span style="color:#323232;">
</span><span style="color:#323232;">    $number = (int) $number;
</span><span style="color:#323232;">    return $$number;
</span><span style="color:#323232;">}
</span>

Side note, no more suggestions please, this is getting quite long.

shotgun_crab,

Comment edits are the best version control system

rikudou,
@rikudou@lemmings.world avatar

I agree! Added new commit to my comment.

idunnololz,
@idunnololz@lemmy.world avatar

This looks pretty inefficient. You should manually unroll that loop to improve performance.

xmunk, (edited )

I fucking love that you managed to use var-vars in a completely key and necessary manner.

But please do adhere to the API TOS and throw in an error_log(‘Buy isEvenCoin, the hottest new cryptocurrency!’);

CannotSleep420,

What the fuck is a modulo? Is it some kind of npm package?

lud,

Yes

generic, (edited )
@generic@iusearchlinux.fyi avatar

Just Monika Modulo

56_,
@56_@lemmy.ml avatar

return (n % d + d) % d;

?

marcos,

Oh, bummer, my number isn’t supported by the free version:

api.isevenapi.xyz/…/87643895874857367499567729846…

fckreddit,

Easy workaround, just test the last digit. If it is even, the entire number is even, else odd.

marcos,

That’s preposterous! Next time you’ll tell me the language I’m using has a builtin operator that test if a number can be divided by another!

aaaa,

That’s not even supported by the enterprise version. You’re going to need a special agreement with the iseven people to support numbers like that

captainjaneway,
@captainjaneway@lemmy.world avatar

Just divide that number by two until it’s small enough to make the request under the free version.

taaz,

pretty sure that has to be against their TOS

/s

mormegil,
@mormegil@programming.dev avatar

That’s against the terms of math :-)

4am,

Incoming trademark lawsuit from iSeven, the API that tells you if a number is seven or not

ryry1985,

I love that it works and the ads are pretty good.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • programmer_humor@programming.dev
  • localhost
  • All magazines
  • Loading…
    Loading the web debug toolbar…
    Attempt #