Last active
April 23, 2021 13:35
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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