We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Day 4: Classes
Day 4: Classes
Sort by
recency
|
279 Discussions
|
Please Login in order to post a comment
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 }) } }
"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.