Skip to content

Optimze/parse attribute #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
optimze: decouple the parseValue
  • Loading branch information
DominguitoLamo committed Nov 11, 2021
commit 3c74805148eb33e2810b6ca5fdae06e3ff081230
15 changes: 13 additions & 2 deletions dist/bundle.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions src/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,20 @@ export function getValueInRange(value: number, min: number, max: number) {
1
);
}

/**
* compose functions into one function from the left to the right
* @param {Array<Function>} func
* @returns {Function}
*/
export function compose(...func: Array<Function>): Function {
if (func.length === 0) {
return (args: any) => args;
}

if (func.length === 1) {
return func[0];
}

return func.reduce((a, b) => (...args: Array<any>) => b(a(...args)));
}
Loading