Tell us what’s happening:
I cannot pass task 10 which instructed that compactedShuffledFragments should be an array with no undefined elements
Your code so far
const shuffledFragments = [
{ id: 15, text: "and, after a time, passed the place where the Hare was sleeping." },
{ id: 12, text: "he lay down beside the course to take a nap" },
,
{ id: 11, text: "and to make the Tortoise feel very deeply how ridiculous it was for him to try a race with a Hare," },
{ id: 7, text: "but for the fun of the thing he agreed." },
{ id: 19, text: "The Hare now ran his swiftest," },
,
{ id: 1, text: "A Hare was making fun of the Tortoise one day for being so slow." },
{ id: 14, text: "The Tortoise meanwhile kept going slowly but steadily," },
{ id: 9, text: "marked the distance and started the runners off." },
,
{ id: 5, text: "I'll run you a race and prove it.\"" },
{ id: 17, text: "and when at last he did wake up," },
{ id: 2, text: '"Do you ever get anywhere?" he asked with a mocking laugh.' },
{ id: 12, text: "he lay down beside the course to take a nap" },
,
{ id: 8, text: "So the Fox, who had consented to act as judge," },
{ id: 20, text: "but he could not overtake the Tortoise in time." },
{ id: 5, text: "I'll run you a race and prove it.\"" },
{ id: 6, text: "The Hare was much amused at the idea of running a race with the Tortoise," },
,
{ id: 13, text: "until the Tortoise should catch up." },
{ id: 10, text: "The Hare was soon far out of sight," },
{ id: 12, text: "he lay down beside the course to take a nap" },
{ id: 18, text: "the Tortoise was near the goal." },
];
function compactFragments(shuffArr){
let compactedShuffledFragments = [];
for(let i =0; i<shuffArr.length; i++){
if(shuffArr[i] === undefined){
console.log("[COMPACTED]")
}
else{
compactedShuffledFragments.push(shuffArr[i])
}
}
return compactedShuffledFragments;
}
const finalFragments = compactFragments([{ id: 1, text: "Hello" }, undefined, { id: 2, text: "World" }]);
console.log(finalFragments);
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/151.0.0.0 Safari/537.36
Challenge Information:
Restore a Coherent Narrative from an Array of Story Fragments - Restore a Coherent Narrative from an Array of Story Fragments