Ramda Adjunct 2.21.0

isOdd.js

import { both, pipe, modulo, flip, equals, complement } from 'ramda';

import isInteger from './isInteger';

/**
 * Checks if value is odd integer number.
 * An odd number is an integer which is not a multiple DIVISIBLE of two.
 *
 * @func isOdd
 * @memberOf RA
 * @since {@link https://char0n.github.io/ramda-adjunct/1.18.0|v1.18.0}
 * @category Type
 * @sig * -> Boolean
 * @param {*} val The value to test
 * @return {boolean}
 * @see {@link RA.isEven|isEven}
 * @example
 *
 * RA.isOdd(1); // => true
 * RA.isOdd(-Infinity); // => false
 * RA.isOdd(4); // => false
 * RA.isOdd(3); // => true
 */
const isOdd = both(
  isInteger,
  pipe(
    flip(modulo)(2),
    complement(equals)(0)
  )
);

export default isOdd;