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

Commit 29d4e14

Browse files
diogorighiKent C. Dodds
authored and
Kent C. Dodds
committed
feat(isOdd): add isOdd function (#110)
add isOdd function that returns true if a number is Odd and false if its not Closes #109
1 parent 10eb532 commit 29d4e14

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
@@ -36,8 +36,10 @@ import endsWith from './endsWith'
3636
import round from './round'
3737
import checkPalindrome from './checkPalindrome'
3838
import isFunction from './is-function'
39+
import isOdd from './is-odd'
3940

4041
export {
42+
isOdd,
4143
isEven,
4244
revstring,
4345
initArray,

src/is-odd.js

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

test/is-odd.test.js

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

0 commit comments

Comments
 (0)