Skip to content

Commit

Permalink
range docs
Browse files Browse the repository at this point in the history
  • Loading branch information
phixid committed Dec 30, 2017
1 parent 582534a commit 75b5fa0
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 18 deletions.
31 changes: 25 additions & 6 deletions dist/cjs/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ const LazyBox = g => ({
* composeLeft takes two functions and composes them from left to right.
* composeRight takes two functions and composes them from right to left.
*
* @param func1
* @param func2
* @param {function} func1
* @param {function} func2
*/

const composeLeft = (func1, func2) => (...args) => func2(func1(...args));
Expand Down Expand Up @@ -74,10 +74,29 @@ const Right = value => ({

const Either = value => (value == null ? Left(value) : Right(value));

const range = (n, o = 0) =>
Array.from(Array(Math.abs(n - o))).map(
(_, index) => (o ? (o > n ? n + index : n - index) : index)
);
// prettier-ignore

/**
* Range returns an array containing numbers starting at the first parameter all the
* way up to, but not including the last parameter.
* example: range(2, 6) --> [2, 3, 4, 5];
*
* When only one parameter is passed in, creates an array of length equal to the parameter starting at zero.
* example: range(4) --> [0, 1, 2, 3];
*
* @param {number} start
* @param {number} end
* @returns {array.<number>}
*/

const range = (start, end = 0) => Array
.from(Array(Math.abs(start - end)))
.map((_, index) => end
? end > start
? start + index
: start - index
: index
);

exports.Box = Box;
exports.LazyBox = LazyBox;
Expand Down
31 changes: 25 additions & 6 deletions dist/es/subterfuge.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ const LazyBox = g => ({
* composeLeft takes two functions and composes them from left to right.
* composeRight takes two functions and composes them from right to left.
*
* @param func1
* @param func2
* @param {function} func1
* @param {function} func2
*/

const composeLeft = (func1, func2) => (...args) => func2(func1(...args));
Expand Down Expand Up @@ -70,9 +70,28 @@ const Right = value => ({

const Either = value => (value == null ? Left(value) : Right(value));

const range = (n, o = 0) =>
Array.from(Array(Math.abs(n - o))).map(
(_, index) => (o ? (o > n ? n + index : n - index) : index)
);
// prettier-ignore

/**
* Range returns an array containing numbers starting at the first parameter all the
* way up to, but not including the last parameter.
* example: range(2, 6) --> [2, 3, 4, 5];
*
* When only one parameter is passed in, creates an array of length equal to the parameter starting at zero.
* example: range(4) --> [0, 1, 2, 3];
*
* @param {number} start
* @param {number} end
* @returns {array.<number>}
*/

const range = (start, end = 0) => Array
.from(Array(Math.abs(start - end)))
.map((_, index) => end
? end > start
? start + index
: start - index
: index
);

export { Box, LazyBox, composeLeft, composeRight, pipeLeft, pipeRight, Either, Left, Right, range };
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"prebuild": "yarn clean:dist",
"precommit": "lint-staged && yarn test:single && yarn build && git add dist/",
"prepublish": "yarn build",
"test": "yarn test:coverage",
"test:coverage": "yarn test:single --coverage",
"test:single": "jest",
"test:watch": "jest --watchAll --verbose",
Expand Down
4 changes: 2 additions & 2 deletions src/composition/compose.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
* composeLeft takes two functions and composes them from left to right.
* composeRight takes two functions and composes them from right to left.
*
* @param func1
* @param func2
* @param {function} func1
* @param {function} func2
*/

export const composeLeft = (func1, func2) => (...args) => func2(func1(...args));
Expand Down
27 changes: 23 additions & 4 deletions src/functions/range.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
export const range = (n, o = 0) =>
Array.from(Array(Math.abs(n - o))).map(
(_, index) => (o ? (o > n ? n + index : n - index) : index)
);
// prettier-ignore

/**
* Range returns an array containing numbers starting at the first parameter all the
* way up to, but not including the last parameter.
* example: range(2, 6) --> [2, 3, 4, 5];
*
* When only one parameter is passed in, creates an array of length equal to the parameter starting at zero.
* example: range(4) --> [0, 1, 2, 3];
*
* @param {number} start
* @param {number} end
* @returns {array.<number>}
*/

export const range = (start, end = 0) => Array
.from(Array(Math.abs(start - end)))
.map((_, index) => end
? end > start
? start + index
: start - index
: index
);

0 comments on commit 75b5fa0

Please sign in to comment.