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

Fixes for the sake of clarity in Composite #5

Open
wants to merge 1 commit into
base: master
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
23 changes: 9 additions & 14 deletions composite/composite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,21 @@ class Team implements ArmyObject {
}

addSoldier(newSoldier: ArmyObject) {
const soldiers = this._soldiers.filter((soldier: ArmyObject, index) => {
return soldier.seq === newSoldier.seq;
})
if (soldiers.length < 1) {
console.log(`Soldier: ${newSoldier.seq} comes in ${this.seq}`);
this._soldiers.push(newSoldier);
} else {
const hasBeen = this._soldiers.includes(deadSoldier);
if (hasBeen) {
console.log('The soldier is already in the team');
return;
}

console.log(`Soldier: ${newSoldier.seq} comes in ${this.seq}`);
this._soldiers.push(newSoldier);
}

soldierGone(deadSoldier: ArmyObject) {
const deads = this._soldiers.map((soldier: ArmyObject, index) => {
if (soldier.seq === deadSoldier.seq) {
return index;
}
})
if (deads.length > 0) {
const deadIndex = this._soldiers.indexOf(deadSoldier);
if (deadIndex > -1) {
console.log(`Soldier: ${deadSoldier.seq} died in the fight`);
this._soldiers.slice(deads[0], 1);
this._soldiers.splice(deadIndex, 1);
} else {
console.log('No one dies');
}
Expand Down