Tell us what’s happening:
My code doesn’t pass
There is probably a bug in this challenge. It involves the code validation at the last test
My guess is, the expected output is wrong.
Your code so far
function compress(str) {
const words = str.split(' ')
const seen = []
const output = []
for(let word of words){
if(seen.includes(word)){
output.push(seen.indexOf(word)+1)
}else{
seen.push(word)
output.push(word)
}
}
return output.join(" ");
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/144.0.0.0 Safari/537.36 Edg/144.0.0.0
Challenge Information:
Daily Coding Challenge - Word Compressor
https://www.freecodecamp.org/learn/daily-coding-challenge/2026-04-24