Skip to content

Commit 67a4003

Browse files
feat: implement div as an operator function
1 parent b3eed71 commit 67a4003

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/div.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @license MIT
3+
* @copyright (c) 2022 Julien Gonzalez <hello@spinjs.com>
4+
*/
5+
6+
const op = require('./_operator');
7+
8+
/**
9+
* @summary
10+
* Functional equivalent of `a / b`.
11+
*
12+
* @example
13+
* map(div(4))([20,40,60,80])
14+
* //=> [5,10,15,20]
15+
*
16+
* @operator
17+
* @function
18+
* @param {number} a
19+
* @param {number} b
20+
* @return {number}
21+
* @see __
22+
*/
23+
module.exports = op((a, b) => a / b);

test/div.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
const testcheck = require('./_check');
2+
const {div: sut, __} = require('..');
3+
4+
const verif = (res, a, b) =>
5+
Object.is(res, a / b);
6+
7+
testcheck('div(a, b)',
8+
['number', 'number'], (a, b) =>
9+
verif(sut(a, b), a, b));
10+
11+
testcheck('div(b)(a)',
12+
['number', 'number'], (a, b) =>
13+
verif(sut(b)(a), a, b));
14+
15+
testcheck('div(a, __)(b)',
16+
['number', 'number'], (a, b) =>
17+
verif(sut(a, __)(b), a, b));

0 commit comments

Comments
 (0)