8000
We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 40102b5 commit 336069dCopy full SHA for 336069d
calculator/calculator.js
@@ -1,25 +1,31 @@
1
-function add () {
2
-
+function add (a, b) {
+ return a + b
3
}
4
5
-function subtract () {
6
+function subtract (a, b) {
+ return a - b
7
8
9
-function sum () {
10
+function sum (array) {
+ return array.reduce((total, num) => total + num, 0)
11
12
13
-function multiply () {
14
+function multiply (array) {
+ return array.reduce((total, num) => total * num)
15
16
17
-function power() {
18
+function power(a, b) {
+ return a ** b
19
20
21
-function factorial() {
22
+function factorial(a) {
+ if (a <= 1) return 1;
23
+ let product = 1;
24
+ while (a > 1) {
25
+ product *= a
26
+ a--
27
+ }
28
+ return product
29
30
31
module.exports = {
0 commit comments