From a9a02a05d42dfe2dd00b0c0d1881a5732e3af7b8 Mon Sep 17 00:00:00 2001 From: Leonardo Suarez Date: Thu, 21 Sep 2017 12:15:49 -0500 Subject: [PATCH] WIP: add new function check number is pair --- src/index.js | 2 ++ src/is-pair.js | 14 ++++++++++++++ test/is-pair.test.js | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 src/is-pair.js create mode 100644 test/is-pair.test.js diff --git a/src/index.js b/src/index.js index 9d36eb1d..545bf721 100644 --- a/src/index.js +++ b/src/index.js @@ -39,6 +39,7 @@ import isFunction from './is-function' import isOdd from './is-odd' import isNumeric from './is-numeric' import max from './max' +import isPair from './is-pair' export { isOdd, @@ -82,4 +83,5 @@ export { subtraction, isNumeric, max, + isPair, } diff --git a/src/is-pair.js b/src/is-pair.js new file mode 100644 index 00000000..689ad6fb --- /dev/null +++ b/src/is-pair.js @@ -0,0 +1,14 @@ +export default isPair + +/** + * Original Source: + * https://stackoverflow.com/questions/5016313/how-to-determine-if-a-number-is-odd-in-javascript + * + * This method will check if a number is odd or not. + * + * @param {Number} value - value to check + * @return {Boolean} - True if n is pair, false if not + */ +function isPair(value) { + return value % 2 === 0 +} diff --git a/test/is-pair.test.js b/test/is-pair.test.js new file mode 100644 index 00000000..26ae8846 --- /dev/null +++ b/test/is-pair.test.js @@ -0,0 +1,16 @@ +import test from 'ava' +import {isPair} from '../src' + +test('checks if number is pair and returns true', t => { + const n = 20 + const expected = true + const actual = isPair(n) + t.deepEqual(actual, expected) +}) + +test('checks if number is pair and returns false', t => { + const n = 25 + const expected = false + const actual = isPair(n) + t.deepEqual(actual, expected) +})