A function that returns the multiplication of the input arguments. Any number of input arguments can be used.
function multiply(...nums){ return nums.reduce((acc, num) => acc * num, 1) }
# def multiply (a,b):# return a * bmultiply = lambda a, b: a * b- function multiply(...nums){
- return nums.reduce((acc, num) => acc * num, 1)
- }
const chai = require("chai"); const assert = chai.assert; describe("Multiply", function() { it(`input: 1`, function() { assert.strictEqual(multiply(1), 1); }); it(`input: 1, 2`, function() { assert.strictEqual(multiply(1, 2), 2); }); it(`input: 1, 2, 3`, function() { assert.strictEqual(multiply(1, 2, 3), 6); }); it(`input: 2, 2, 2, 2`, function() { assert.strictEqual(multiply(2, 2, 2, 2), 16); }); });
import codewars_test as test# TODO Write testsimport solution # or from solution import example- const chai = require("chai");
- const assert = chai.assert;
# test.assert_equals(actual, expected, [optional] message)@test.describe("Example")def test_group():@test.it("test case")def test_case():test.assert_equals(1 + 1, 2)- describe("Multiply", function() {
- it(`input: 1`, function() {
- assert.strictEqual(multiply(1), 1);
- });
- it(`input: 1, 2`, function() {
- assert.strictEqual(multiply(1, 2), 2);
- });
- it(`input: 1, 2, 3`, function() {
- assert.strictEqual(multiply(1, 2, 3), 6);
- });
- it(`input: 2, 2, 2, 2`, function() {
- assert.strictEqual(multiply(2, 2, 2, 2), 16);
- });
- });