-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* ✨ Add math.divide * ✨ Add math.multiply * ✨ Add math.subtract
- Loading branch information
Showing
7 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _divide from 'lodash/divide' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Replaces by the division of the former number and the given number. | ||
* @function | ||
* @memberof math | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} divisor The second number in the division. | ||
* @return {Object} Returns the updated object. | ||
* @example divide({ nested: { prop: 1332 } }, 'nested.prop', 2) // => { nested: { prop: 666 } } | ||
* @see {@link https://lodash.com/docs#divide|lodash.divide} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const divide = convert(_divide) | ||
export { divide, divide as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-env jest */ | ||
import { divide } from './divide' | ||
import { immutaTest } from 'test.utils' | ||
|
||
describe('Divide', () => { | ||
|
||
it('should divide two numbers', () => { | ||
immutaTest((input, path) => { | ||
const output = divide(input, path, 2) | ||
expect(output).toEqual({ | ||
nested: { prop: 666 }, // 😈 | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: 1332 }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _multiply from 'lodash/multiply' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Replaces by the multiplication of the former number and the given number. | ||
* @function | ||
* @memberof math | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} multiplicand The second number in the multiplication. | ||
* @return {Object} Returns the updated object. | ||
* @example multiply({ nested: { prop: 333 } }, 'nested.prop', 2) // => { nested: { prop: 666 } } | ||
* @see {@link https://lodash.com/docs#multiply|lodash.multiply} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const multiply = convert(_multiply) | ||
export { multiply, multiply as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { multiply } from './multiply' | ||
|
||
describe('Multiply', () => { | ||
|
||
it('should multiply two numbers', () => { | ||
immutaTest((input, path) => { | ||
const output = multiply(input, path, 2) | ||
expect(output).toEqual({ | ||
nested: { prop: 666 }, // 😈 | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: 333 }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import _subtract from 'lodash/subtract' | ||
import { convert } from 'util/convert' | ||
|
||
/** | ||
* Replaces by the subtraction of the former number by the given number. | ||
* @function | ||
* @memberof math | ||
* @param {Object} object The object to modify. | ||
* @param {Array|string} path The path of the property to set. | ||
* @param {number} subtrahend The number to subtract. | ||
* @return {Object} Returns the updated object. | ||
* @example subtract({ nested: { prop: 2000 } }, 'nested.prop', 336) // => { nested: { prop: 1664 } } | ||
* @see {@link https://lodash.com/docs#subtract|lodash.subtract} for more information. | ||
* @since 0.3.0 | ||
*/ | ||
const subtract = convert(_subtract) | ||
export { subtract, subtract as default } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
/* eslint-env jest */ | ||
import { immutaTest } from 'test.utils' | ||
import { subtract } from './subtract' | ||
|
||
describe('Subtract', () => { | ||
|
||
it('should subtract two numbers', () => { | ||
immutaTest((input, path) => { | ||
const output = subtract(input, path, 336) | ||
expect(output).toEqual({ | ||
nested: { prop: 1664 }, // 🍺 | ||
other: {}, | ||
}) | ||
return output | ||
}, { | ||
nested: { prop: 2000 }, | ||
other: {}, | ||
}, 'nested.prop') | ||
}) | ||
}) |