Skip to content

Instantly share code, notes, and snippets.

@guz-anton
Created August 2, 2021 12:25
Show Gist options
  • Save guz-anton/cd0df2f7e7605b387194f58d0c7a3b3d to your computer and use it in GitHub Desktop.
Save guz-anton/cd0df2f7e7605b387194f58d0c7a3b3d to your computer and use it in GitHub Desktop.
const fx = (fn, start, ...xn) => {
const FF = class {
constructor (...rn) {
const ww = (...wn) => { return new FF(...rn, ...wn)}
ww.valueOf = () => this.valueOf()
ww.toString = () => this.toString()
this.items = rn
return ww
}
value() {return this.items.reduce(fn, start)}
valueOf () {return this.value() - 0}
toString () {return this.value() + ''}
}
return new FF(...xn)
}
const fx = (fn, start, ...xn) => {
let value;
const fy = (...yn) => {
value = [...xn, ...yn].reduce(fn, start);
return fy;
};
fy.valueOf = () => {return value - 0};
fy.toString = () => {return value + ''};
return fy;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment