Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reactored Vampire #11

Open
wants to merge 2 commits into
base: traversal
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions vampire.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,21 +10,32 @@ class Vampire {

// Adds the vampire as an offspring of this vampire
addOffspring(vampire) {

this.offspring.push(vampire);
vampire.creator = this;
}

// Returns the total number of vampires created by that vampire
get numberOfOffspring() {

return this.offspring.length;
}

// Returns the number of vampires away from the original vampire this vampire is
get numberOfVampiresFromOriginal() {
let numberOfVampires = 0;
let currentVampire = this;

// climb "up" the tree (using iteration), counting nodes, until no original is found
while (currentVampire.creator) {
currentVampire = currentVampire.creator;
numberOfVampires++;
}

return numberOfVampires;
}

// Returns true if this vampire is more senior than the other vampire. (Who is closer to the original vampire)
isMoreSeniorThan(vampire) {
return (this.numberOfVampiresFromOriginal < vampire.numberOfVampiresFromOriginal);

}

Expand All @@ -40,5 +51,6 @@ class Vampire {
}
}


module.exports = Vampire;