Day 4 : Classes
Theory
This syntax is a means of more simply and clearly creating objects and deal with inheritance. There are 2 ways to define classes:
Class declaration - Use
class
keyword and follow with class name (TitleCase) (class Polygon {....})Class Expression - only difference is " let Polygon = class ... "
A class can only have one constructor (special method)
https://www.hackerrank.com/challenges/js10-class/topics
Task
Create a Polygon class that has the following properties:
A constructor that takes an array of integer values describing the lengths of the polygon's sides.
A perimeter() method that returns the polygon's perimeter.
We also learnt to use .reduce method
The reduce()
method executes a user-supplied “reducer” callback function on each element of the array, in order, passing in the return value from the calculation on the preceding element. The final result of running the reducer across all elements of the array is a single value
Last updated