-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #28 from yusufshakeel/dev
0.8.15
- Loading branch information
Showing
7 changed files
with
117 additions
and
18 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
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
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 |
---|---|---|
@@ -1,5 +1,54 @@ | ||
'use strict'; | ||
|
||
/** | ||
* This will sum up the values. | ||
* @param {number[]} values | ||
* @returns {number} | ||
*/ | ||
const sumOf = values => values.reduce((sum, size) => sum + size, 0); | ||
|
||
module.exports = { sumOf }; | ||
/** | ||
* This will attach prefix to the coupon. | ||
* @param {string} prefix | ||
* @returns {function(string): string} | ||
*/ | ||
const attachPrefix = (prefix = '') => coupon => `${prefix}${coupon}`; | ||
|
||
/** | ||
* This will attach suffix to the coupon. | ||
* @param {string} suffix | ||
* @returns {function(string): string} | ||
*/ | ||
const attachSuffix = (suffix = '') => coupon => `${coupon}${suffix}`; | ||
|
||
/** | ||
* This will take in an array of operators to operate on a value. | ||
* @param {*} operators | ||
* @returns {function(*=): *} | ||
*/ | ||
const pipe = operators => value => | ||
operators.reduce((enrichedValue, operator) => operator(enrichedValue), value); | ||
|
||
/** | ||
* This will return the first argument it receives. | ||
* @param {*} value | ||
* @returns {*} | ||
*/ | ||
const identity = value => value; | ||
|
||
/** | ||
* This will omit the specified values. | ||
* @param {string[]} values | ||
* @param {string[]} valuesToOmit | ||
* @returns {string[]} | ||
*/ | ||
const omit = (values, valuesToOmit) => values.filter(value => !valuesToOmit.includes(value)); | ||
|
||
/** | ||
* This will return unique characters array. | ||
* @param {string[]} characters | ||
* @returns {string[]} | ||
*/ | ||
const uniqueCharacters = characters => [...new Set(characters.join(''))]; | ||
|
||
module.exports = { sumOf, attachPrefix, attachSuffix, pipe, identity, omit, uniqueCharacters }; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,7 +1,56 @@ | ||
'use strict'; | ||
|
||
const { sumOf } = require('../../../../app/functional'); | ||
const { | ||
sumOf, | ||
attachSuffix, | ||
attachPrefix, | ||
pipe, | ||
identity, | ||
omit, | ||
uniqueCharacters | ||
} = require('../../../../app/functional'); | ||
|
||
test('Should be able to sum up', () => { | ||
expect(sumOf([1, 2, 3])).toBe(6); | ||
}); | ||
|
||
test('Should be able to attach prefix', () => { | ||
expect(attachPrefix('HELLO')('COUPON')).toBe('HELLOCOUPON'); | ||
expect(attachPrefix()('COUPON')).toBe('COUPON'); | ||
}); | ||
|
||
test('Should be able to attach suffix', () => { | ||
expect(attachSuffix('WORLD')('COUPON')).toBe('COUPONWORLD'); | ||
expect(attachSuffix()('COUPON')).toBe('COUPON'); | ||
}); | ||
|
||
test('Should be able to attach prefix and suffix in that order using pipe function', () => { | ||
expect(pipe([attachPrefix('HELLO'), attachSuffix('WORLD')])('COUPON')).toBe('HELLOCOUPONWORLD'); | ||
}); | ||
|
||
test('Should be able to return the first argument it receives using identity function', () => { | ||
expect(identity('foo')).toBe('foo'); | ||
expect(identity(1)).toBe(1); | ||
expect(identity(null)).toBe(null); | ||
expect(identity(undefined)).toBe(undefined); | ||
expect(identity({ foo: 'bar' })).toStrictEqual({ foo: 'bar' }); | ||
expect(identity(true)).toBeTruthy(); | ||
expect(identity(false)).toBeFalsy(); | ||
}); | ||
|
||
test('Should be able to omit values', () => { | ||
const values = ['A', 'B', 'C', 'D', 'E', 'F']; | ||
const valuesToOmit = ['A', 'B', 'F']; | ||
expect(omit(values, valuesToOmit)).toStrictEqual(['C', 'D', 'E']); | ||
}); | ||
|
||
test('Should be able to get unique characters', () => { | ||
expect(uniqueCharacters(['ABC', 'CD', 'EB', 'ACF'])).toStrictEqual([ | ||
'A', | ||
'B', | ||
'C', | ||
'D', | ||
'E', | ||
'F' | ||
]); | ||
}); |