StaffList

    0

    0

    The StaffList class contains a map of staff members. The constructor creates the map and the add and remove methods add and delete staff members based on their name and age. The getSize method returns the size of the StaffList map.

    class StaffList {
      constructor() {
        this.staff = new Map();
      }
      add(name, age) {
        if (age > 20) {
          this.staff.set(name, age);
        } else {
          throw new Error(`Staff member age must be greater than 20`);
        }
      }
      remove(name) {
        if (this.staff.has(name)) {
          this.staff.delete(name);
          return true;
        } else {
          return false;
        }
      }
      getSize() {
        return this.staff.size;
      }
    }
    
    Codiga Logo
    Codiga Hub
    • Rulesets
    • Playground
    • Snippets
    • Cookbooks
    soc-2 icon

    We are SOC-2 Compliance Certified

    G2 high performer medal

    Codiga – All rights reserved 2022.