class Calculator { constructor(numbers = [], num1, num2) { this.numbers = numbers; this.num1 = num1; this.num2 = num2; } add() { for (let i = 0; i < this.numbers.length; i++) { if(typeof this.numbers[i] === "number") { return this.numbers[i].reduce((a,b) => a + b, 0) } } return this; } multiply () { for (let i = 0; i < this.numbers.length; i++) { if(typeof this.numbers[i] === "number") { return this.numbers[i].reduce((a,b) => a * b, 1) } } return this; } subtract () { return this.num1 - this.num2 } divide () { return this.num1 / this.num2 } }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter