Sort by

recency

|

279 Discussions

|

  • + 0 comments

    This is my Solution . I tried to use the reduce() method to sum the element , in this case the numbers in the give array. the method takes a callback function as well as the array itself(optional) for which we call the reduce() , the callback function takes 3 param. (previousValue , currentIndexValue , currentIndex(optional) ) and return the result (a number) . class Polygon{ constructor(lenghts){
    this.lenghts = lenghts; } perimeter(){ return this.lenghts.reduce((total , currentValue)=>{return total + currentValue }) } }

  • + 0 comments
    class Polygon {
        constructor(sides) {
            this.sides = sides;
        }
        
        perimeter() {
            return this.sides.reduce((acc, curr)=> acc+curr, 0);
        }
    }
    
  • + 0 comments
    class Polygon {
      constructor(length) {
        this.length = length;
      }
    
      perimeter() {
        let sum = 0;
        for (let i = 0; i < this.length.length; i++) {
         sum += this.length[i];
        }
    		
    		
        return sum;
      }
    }
    
  • + 0 comments

    "Singleton Class Using a Function" has incorrect information in the "Topics".

    The given example creates an object, similarly as if one would do:

    myObject = {a:1};

    It doesn't create a singleton.

  • + 0 comments
    class Polygon {
        constructor(sides) {
            this.sides = sides
        }
        perimeter() {
            let sides = this.sides
          return sides.reduce((side, accum) => accum += side, 0)
        }
    }