Last active
February 2, 2020 22:10
-
-
Save infusion/dac3147a13a8ad6ee0e1 to your computer and use it in GitHub Desktop.
An implementation of primitive operations like addition, multiplication and so on - recursively!
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
/** | |
* @license Recursive-Primitive.js | |
* | |
* Copyright (c) 2014, Robert Eisele ([email protected]) | |
* Dual licensed under the MIT or GPL Version 2 licenses. | |
**/ | |
const add = (a, b) => b === 0 ? a : add(a + 1, b - 1); | |
const sub = (a, b) => b === 0 ? a : sub(a - 1, b - 1); | |
const mul = (a, b) => b === 1 ? a : add(mul(a, b - 1), a); | |
const div = (a, b) => b === 0 || a < b ? 0 : add(div(sub(a, b), b), 1); | |
const mod = (a, b) => a < b ? a : mod(sub(a, b), b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment