From 82827a300bc734944cbded885ebec5c7a00c8994 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 13 Jul 2019 21:27:40 +0200 Subject: [PATCH] extend basic math function to multi params --- desktop/sources/scripts/library.js | 16 ++++++++-------- examples/math.lisp | 5 +++++ 2 files changed, 13 insertions(+), 8 deletions(-) create mode 100644 examples/math.lisp diff --git a/desktop/sources/scripts/library.js b/desktop/sources/scripts/library.js index 647d6a6..3b4debca 100644 --- a/desktop/sources/scripts/library.js +++ b/desktop/sources/scripts/library.js @@ -94,18 +94,18 @@ function Library (ronin) { // Math - this.add = function (a, b) { - return a + b + this.add = function (...args) { + return args.reduce((sum, val) => sum + val) } - this.sub = function (a, b) { - return a - b + this.sub = function (...args) { + return args.reduce((sum, val) => sum - val) } - this.mul = function (a, b) { - return a * b + this.mul = function (...args) { + return args.reduce((sum, val) => sum * val) } - this.div = function (a, b) { - return a / b + this.div = function (...args) { + return args.reduce((sum, val) => sum / val) } } diff --git a/examples/math.lisp b/examples/math.lisp new file mode 100644 index 0000000..7a6906e --- /dev/null +++ b/examples/math.lisp @@ -0,0 +1,5 @@ +( + (echo (add 2 3)) + (echo (sub 22 3 4 5)) + (echo (mul 2 3 4 5)) +) \ No newline at end of file