Merge pull request #32 from lctrt/feat/math-extension

extend basic math function to multi params
This commit is contained in:
Лu Лinveгa 2019-07-14 09:12:21 +12:00 committed by GitHub
commit 7a30b60a8c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 9 deletions

View File

@ -144,20 +144,20 @@ 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)
}
this.mod = function (a, b) {

5
examples/math.lisp Normal file
View File

@ -0,0 +1,5 @@
(
(echo (add 2 3))
(echo (sub 22 3 4 5))
(echo (mul 2 3 4 5))
)