number-fifteen
Version:
Natural number 15 (defined as 15 KB divided by 1 KB)
39 lines (33 loc) • 1.16 kB
JavaScript
const aboutFifteenKilos = require("fifteen-kilos");
const aboutOneKilo = `
/*!
* is-odd <https://github.com/jonschlinkert/is-odd>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
// Here we import the is number library
const isNumber = require('is-number');
module.exports = function isOdd(value) {
// here we take the absolute value
const n = Math.abs(value);
if (!isNumber(n)) {
// here we throw an error if the input is not a number
throw new TypeError('expected a number');
}
// here expect intereger
if (!Number.isInteger(n)) {
throw new Error('expected an integer');
}
//here we exåect safe interger to be inputted as the input
if (!Number.isSafeInteger(n)) {
throw new Error('value exceeds maximum safe integer');
}
// now this is where the magic happens
// every odd number x and only odd numbers x can be represented as x = 2k + 1 where k is some integer
// this means that the reminder of x divided by two is one excactly when x is an odd number
return (n % 2) === 1;
};
`;
module.exports = Math.round(aboutFifteenKilos.length / aboutOneKilo.length);