Skip to content

Instantly share code, notes, and snippets.

@Yago
Last active November 28, 2018 13:44
Show Gist options
  • Save Yago/6f08437b368918603b5e311144af25e9 to your computer and use it in GitHub Desktop.
Save Yago/6f08437b368918603b5e311144af25e9 to your computer and use it in GitHub Desktop.
class Calculator {
constructor(origin) {
this.origin = origin;
}
sum(...args) {
return args.reduce((acc, n) => typeof n === 'number' ? acc + n : acc, this.origin);
}
}
const Hal = new Calculator(31);
Hal.sum(7, 4); // return 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment