编写一个符合此规范的Summation功能mixin

时间:2019-01-24 18:27:22

标签: javascript

我的问题是写一个与该规范匹配的withSummation函数mixin

 enter code here

    "use strict";

    // Setup Mocha and Chai
    mocha.setup( "bdd" );`enter code here`
    var expect = chai.expect;

    describe( "withSummation", function(){`enter code here`
      it( "should be a function", function(){
        expect( withSummation ).to.be.a( "function" );
      } );

      it( "returns the Σ of 1 through 4", function(){
        var calculator = new Calculator();
        expect( calculator ).to.not.have.property( "sum" );
        withSummation.call( calculator );
        expect( calculator ).to.have.property( "sum" ).that.is.a( "function" );
        expect( calculator.sum( 1, 2, 3, 4 ) ).to.equal( 10 );
      } );
    } );

以下是我更新的解决方案。谢谢

    function withSummation (sum) {
  this.sum = (...arr) => {return arr.reduce((a,b) => { return a + b});
}}

0 个答案:

没有答案