curriculum/challenges/english/blocks/workshop-space-mission-roster/695a43cc94b29c92227efd46.md
You added a console.log() call to your script to validate your EVAChunks array, and now the call is no longer needed. To keep the terminal clean for the next steps, delete the for loop block that logs data from EVAChunks.
You should remove the for loop block that logs data from EVAChunks. Delete the whole block containing both loops.
const solution = (`constsquad=[];constfirstAstronaut={id:1,name:"Andy",role:"Commander",isEVAEligible:true,priority:3};functionaddCrewMember(crew,astronaut){for(leti=0;i<crew.length;i++){if(crew[i].id===astronaut.id){console.log("DuplicateID:"+astronaut.id);return;}}crew.push(astronaut);}addCrewMember(squad,firstAstronaut);constremainingCrew=[{id:2,name:"Bart",role:"Pilot",isEVAEligible:false,priority:8},{id:3,name:"Caroline",role:"Engineer",isEVAEligible:true,priority:4},{id:4,name:"Diego",role:"Scientist",isEVAEligible:false,priority:1},{id:5,name:"Elise",role:"Medic",isEVAEligible:true,priority:7},{id:6,name:"Felix",role:"Navigator",isEVAEligible:true,priority:6},{id:7,name:"Gertrude",role:"Communications",isEVAEligible:false,priority:4},{id:8,name:"Hank",role:"Mechanic",isEVAEligible:true,priority:2},{id:9,name:"Irene",role:"Specialist",isEVAEligible:true,priority:5},{id:10,name:"Joan",role:"Technician",isEVAEligible:false,priority:1},];for(leti=0;i<remainingCrew.length;i++){addCrewMember(squad,remainingCrew[i]);}functionswapCrewMembers(crew,fromIndex,toIndex){if(fromIndex<0||toIndex<0||fromIndex>=crew.length||toIndex>=crew.length){console.log("Invalidcrewindices");return;}constupdatedCrew=crew.slice();updatedCrew[fromIndex]=updatedCrew.splice(toIndex,1,updatedCrew[fromIndex])[0];returnupdatedCrew;}constupdatedSquad=swapCrewMembers(squad,2,5);functionsortByPriorityDescending(crew){for(leti=0;i<crew.length-1;i++){for(letj=0;j<crew.length-1-i;j++){if(crew[j].priority<crew[j+1].priority){consttemp=crew[j];crew[j]=crew[j+1];crew[j+1]=temp;}}}}functiongetEVAReadyCrew(crew){consteligible=[];for(constastronautofcrew){if(astronaut.isEVAEligible)eligible.push(astronaut);}sortByPriorityDescending(eligible);returneligible;}constEVAReadySquad=getEVAReadyCrew(updatedSquad);functionchunkCrew(crew,size){if(size<1){console.log("Chunksizemustbe>=1");return;}constchunks=[];for(leti=0;i<crew.length;i+=size){chunks.push(crew.slice(i,i+size));}returnchunks;}constEVAChunks=chunkCrew(EVAReadySquad,3);`);
const cleaned = __helpers.removeWhiteSpace(__helpers.removeJSComments(code));
assert.strictEqual(cleaned, solution);
const squad = [];
const firstAstronaut = {
id: 1,
name: "Andy",
role: "Commander",
isEVAEligible: true,
priority: 3
};
function addCrewMember(crew, astronaut) {
for (let i = 0; i < crew.length; i++) {
if (crew[i].id === astronaut.id) {
console.log("Duplicate ID: " + astronaut.id);
return;
}
}
crew.push(astronaut);
}
addCrewMember(squad, firstAstronaut);
const remainingCrew = [
{ id: 2, name: "Bart", role: "Pilot", isEVAEligible: false, priority: 8 },
{ id: 3, name: "Caroline", role: "Engineer", isEVAEligible: true, priority: 4 },
{ id: 4, name: "Diego", role: "Scientist", isEVAEligible: false, priority: 1 },
{ id: 5, name: "Elise", role: "Medic", isEVAEligible: true, priority: 7 },
{ id: 6, name: "Felix", role: "Navigator", isEVAEligible: true, priority: 6 },
{ id: 7, name: "Gertrude", role: "Communications", isEVAEligible: false, priority: 4 },
{ id: 8, name: "Hank", role: "Mechanic", isEVAEligible: true, priority: 2 },
{ id: 9, name: "Irene", role: "Specialist", isEVAEligible: true, priority: 5 },
{ id: 10, name: "Joan", role: "Technician", isEVAEligible: false, priority: 1 },
];
for (let i = 0; i < remainingCrew.length; i++) {
addCrewMember(squad, remainingCrew[i]);
}
function swapCrewMembers(crew, fromIndex, toIndex) {
if (
fromIndex < 0 ||
toIndex < 0 ||
fromIndex >= crew.length ||
toIndex >= crew.length
) {
console.log("Invalid crew indices");
return;
}
const updatedCrew = crew.slice();
updatedCrew[fromIndex] = updatedCrew.splice(toIndex, 1, updatedCrew[fromIndex])[0];
return updatedCrew;
}
const updatedSquad = swapCrewMembers(squad, 2, 5);
function sortByPriorityDescending(crew) {
for (let i = 0; i < crew.length - 1; i++) {
for (let j = 0; j < crew.length - 1 - i; j++) {
if (crew[j].priority < crew[j + 1].priority) {
const temp = crew[j];
crew[j] = crew[j + 1];
crew[j + 1] = temp;
}
}
}
}
function getEVAReadyCrew(crew) {
const eligible = [];
for (const astronaut of crew) {
if (astronaut.isEVAEligible) eligible.push(astronaut);
}
sortByPriorityDescending(eligible);
return eligible;
}
const EVAReadySquad = getEVAReadyCrew(updatedSquad);
function chunkCrew(crew, size) {
if (size < 1) {
console.log("Chunk size must be >= 1");
return;
}
const chunks = [];
for (let i = 0; i < crew.length; i += size) {
chunks.push(crew.slice(i, i + size));
}
return chunks;
}
const EVAChunks = chunkCrew(EVAReadySquad, 3);
--fcc-editable-region--
for (let i = 0; i < EVAChunks.length; i++) {
console.log(`Chunk ${i + 1}:`);
for (let j = 0; j < EVAChunks[i].length; j++) {
console.log(EVAChunks[i][j].name);
}
}
--fcc-editable-region--