Skip to content

Instantly share code, notes, and snippets.

@yhunko
Last active April 23, 2021 13:35
Show Gist options
  • Save yhunko/04124a216442618330de842c17594fbf to your computer and use it in GitHub Desktop.
Save yhunko/04124a216442618330de842c17594fbf to your computer and use it in GitHub Desktop.
Fun solution for a task on Codewars. https://www.codewars.com/kata/525f3eda17c7cd9f9e000b39
var numbers = [
"zero",
"one",
"two",
"three",
"four",
"five",
"six",
"seven",
"eight",
"nine",
];
var operations = [
{
name: "plus",
action: "+",
},
{ name: "minus", action: "-" },
{ name: "times", action: "*" },
{ name: "dividedBy", action: "/" },
];
var that = typeof window === "undefined" ? this : window;
numbers.forEach(function (name, index) {
that[name] = function (action) {
return action ? eval("Math.round(" + index + action + ")") : index;
};
});
operations.forEach(function (operation) {
that[operation.name] = function (right) {
return operation.action + right;
};
});
console.log(one(plus(one())));
console.log(eight(dividedBy(three())));
console.log(seven(times(five())));
console.log(four(plus(nine())));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment