News for hackers. Stuff that matters.
Re:4B If Statements by arzig on Thursday December 28, 2023 @09:08AM (#38793597)
I have not read the source but I had always assumed that this was the lovingly crafted effort of someone who is intimately familiar with the js standard making sure that some hypothetical expression like ![1] is neither odd nor even. Surely the idea that modulo is beyond developers is too horrifying to contemplate.
Re:4B If Statements by umanwizard on Thursday December 28, 2023 @11:24AM (#38795070)
Here you go:

    /*!
     * is-odd <https://github.com/jonschlinkert/is-odd>
     *
     * Copyright (c) 2015-2017, Jon Schlinkert.
     * Released under the MIT License.
     */
    
    'use strict';
    
    const isNumber = require('is-number');
    
    module.exports = function isOdd(value) {
      const n = Math.abs(value);
      if (!isNumber(n)) {
        throw new TypeError('expected a number');
      }
      if (!Number.isInteger(n)) {
        throw new Error('expected an integer');
      }
      if (!Number.isSafeInteger(n)) {
        throw new Error('value exceeds maximum safe integer');
      }
      return (n % 2) === 1;
    };
It does some checking the `value` is an integer in the safe range, which doesn't even seem right to me. Why shouldn't you be able to call this on integers outside the save range?
Re:4B If Statements by addaon on Thursday December 28, 2023 @11:50AM (#38795375)
All non-safe integers are even, yes?
Re:4B If Statements by johnfn on Thursday December 28, 2023 @02:00PM (#38797140)
(10e15 + 1) % 2 === 0
Re:4B If Statements by fifilura on Thursday December 28, 2023 @10:01AM (#38794009)
Sad but true. For JavaScript these kind of functions can actually be useful because of all the quirks. If that was the GPs hint then I can understand.