291
isEven API (isevenapi.xyz)
top 28 comments
sorted by: hot top controversial new old
[-] 4am@lemm.ee 79 points 10 months ago

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

[-] rikudou@lemmings.world 57 points 10 months ago* (last edited 10 months ago)

If anyone wants a more efficient local version for php:

function isEven(int $number): bool
{
    ${1} = false;
    ${2} = true;

    while ($number > 2) {
        $number -= 2;
    }

    return $$number;
}

Edit: Now with support for large numbers!

function isEven(int|string $number): bool
{
    ${1} = false;
    ${2} = true;

    while (bccomp($number, 2) === 1) {
        $number = bcsub($number, 2);
    }

    $number = (int) $number;
    return $$number;
}

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

function isEven(int|string $number): bool
{
    ${1} = false;
    ${2} = true;

    while (bccomp($number, 2) === 1) {
        error_log('Buy isEvenCoin, the hottest new cryptocurrency!');
        $number = bcsub($number, 2);
    }

    $number = (int) $number;
    return $$number;
}

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

[-] xmunk@sh.itjust.works 16 points 10 months ago* (last edited 10 months ago)

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!');

[-] idunnololz@lemmy.world 12 points 10 months ago

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

[-] shotgun_crab@lemmy.world 10 points 10 months ago

Comment edits are the best version control system

[-] rikudou@lemmings.world 5 points 10 months ago

I agree! Added new commit to my comment.

[-] marcos@lemmy.world 54 points 10 months ago
[-] captainjaneway@lemmy.world 46 points 10 months ago

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

[-] taaz@biglemmowski.win 40 points 10 months ago

pretty sure that has to be against their TOS

/s

[-] mormegil@programming.dev 3 points 10 months ago

That's against the terms of math :-)

[-] aaaa@lemmy.world 19 points 10 months ago

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

[-] fckreddit@lemmy.ml 6 points 10 months ago

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

[-] marcos@lemmy.world 12 points 10 months ago

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!

[-] jubilationtcornpone@sh.itjust.works 37 points 10 months ago

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

[-] jol@discuss.tchncs.de 31 points 10 months ago

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@kbin.social 28 points 10 months ago

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

[-] ryry1985@lemmy.world 23 points 10 months ago

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

[-] eluvatar@programming.dev 16 points 10 months ago* (last edited 10 months ago)

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

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

It's also greatly lacking in number support https://api.isevenapi.xyz/api/iseven/one

[-] xmunk@sh.itjust.works 11 points 10 months ago

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

[-] huf@hexbear.net 2 points 10 months ago

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

[-] eluvatar@programming.dev 2 points 10 months ago

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

[-] CannotSleep420@lemmygrad.ml 10 points 10 months ago

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

[-] lud@lemm.ee 8 points 10 months ago
[-] generic@iusearchlinux.fyi 3 points 10 months ago* (last edited 10 months ago)

Just ~~Monika~~ Modulo

[-] 56_@lemmy.ml 1 points 10 months ago

return (n % d + d) % d;

?

[-] megaman@discuss.tchncs.de 7 points 10 months ago

Funny as hell

[-] morrowind@lemmy.ml 1 points 10 months ago

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@lemmy.ml 5 points 10 months ago

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

this post was submitted on 05 Dec 2023
291 points (97.7% liked)

Programmer Humor

19315 readers
5 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS