Skip to content

Instantly share code, notes, and snippets.

@m4n50n
Created December 20, 2021 20:20
Show Gist options
  • Save m4n50n/6cb87357249d5bed8b4e28181c29b292 to your computer and use it in GitHub Desktop.
Save m4n50n/6cb87357249d5bed8b4e28181c29b292 to your computer and use it in GitHub Desktop.
Calculating with Functions - Codewars Kata
function zero(param) { return (!param) ? 0 : param(0); } // param = plus / minus ...
function one(param) { return (!param) ? 1 : param(1); }
function two(param) { return (!param) ? 2 : param(2); }
function three(param) { return (!param) ? 3 : param(3); }
function four(param) { return (!param) ? 4 : param(4); }
function five(param) { return (!param) ? 5 : param(5); }
function six(param) { return (!param) ? 6 : param(6); }
function seven(param) { return (!param) ? 7 : param(7); }
function eight(param) { return (!param) ? 8 : param(8); }
function nine(param) { return (!param) ? 9 : param(9); }
function plus(inicial_num) {
return function (final_num) {
return inicial_num + final_num;
}
}
function minus(inicial_num) {
return function (final_num) {
return final_num - inicial_num;
}
}
function times(inicial_num) {
return function (final_num) {
return inicial_num * final_num;
}
}
function dividedBy(inicial_num) {
return function (final_num) {
return parseInt(final_num / inicial_num);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment