Ad

tried to add very simple modern family structure. may include ordinary parents, single parents, biological & social parents, .....

Code
Diff
  • class Human {
      constructor (firstName = '', lastName = '') {
        this.firstName = firstName;
        this.lastName = lastName;
        this.parents = [];  // modern family. who takes parental care?
      }
      filterMyFamily(humans) {
        return humans.filter(human => human.lastName === this.lastName)
      }
      
      addParent(p){
        if (!this.hasParent(p)) this.parents.push(p);
        return this;
      }
      
      hasChild(c){
        return c.hasParent(this);
      }
      
      hasParent(p){
        for (var i=0; i<this.parents.length; i++){
          if (this.parents[i] === p) return true;
        }
        return false;
      }
    }
    • class Human {
    • constructor (firstName = '', lastName = '') {
    • this.firstName = firstName;
    • this.lastName = lastName;
    • this.parents = []; // modern family. who takes parental care?
    • }
    • filterMyFamily(humans) {
    • return humans.filter(human => human.lastName === this.lastName)
    • }
    • addParent(p){
    • if (!this.hasParent(p)) this.parents.push(p);
    • return this;
    • }
    • hasChild(c){
    • return c.hasParent(this);
    • }
    • hasParent(p){
    • for (var i=0; i<this.parents.length; i++){
    • if (this.parents[i] === p) return true;
    • }
    • return false;
    • }
    • }