Skip to content
This repository was archived by the owner on Feb 20, 2019. It is now read-only.

Commit 10f1e42

Browse files
GeoDooKent C. Dodds
authored and
Kent C. Dodds
committed
feat(isEven): Add isEven function (#103)
* feat(isEven): Add isEven function Add isEven function which checks if a given number is even or not * feat(isEven): Add isEven function Add isEven function which checks if a given number is even or not Closed #101
1 parent 0251f0f commit 10f1e42

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

src/index.js

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isEven from './is-even'
12
import revstring from './revstring'
23
import initArray from './init-array'
34
import reduce from './reduce-to-tally'
@@ -35,6 +36,7 @@ import round from './round'
3536
import checkPalindrome from './checkPalindrome'
3637

3738
export {
39+
isEven,
3840
revstring,
3941
initArray,
4042
reduce,

src/is-even.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
export default isEven
2+
3+
/**
4+
* Original Source:
5+
* https://stackoverflow.com/questions/16929958/how-to-determine-if-a-number-is-odd-or-even-in-java-script
6+
*
7+
* This method will check if a number is even or not.
8+
*
9+
* @param {Number} n - number to check
10+
* @return {Boolean} - True if n is even, false if not
11+
*/
12+
function isEven(n) {
13+
return n === parseFloat(n) && !(n % 2)
14+
}

test/is-even.test.js

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import test from 'ava'
2+
import {isEven} from '../src'
3+
4+
test('checks if number is even and returns true', t => {
5+
const n = 26
6+
const expected = true
7+
const actual = isEven(n)
8+
t.deepEqual(actual, expected)
9+
})
10+
11+
test('checks if number is even and returns false', t => {
12+
const n = 27
13+
const expected = false
14+
const actual = isEven(n)
15+
t.deepEqual(actual, expected)
16+
})

0 commit comments

Comments
 (0)