Today's puzzle
What's missing in this code?
processWords('number', ['1', '2', '2', '2', '3']); // 2umber n
processWords('elephant', ['ant', 'ant', 'ant', 'bee']); // alephant ent
processWords('nope', ['hello', 'hello', 'hello', 'bye']); // hope nello
processWords('nope', ['hello', 'hello', 'bye', 'bye']); // null
processWords('nope', ['hello', 'bye', 'bye', 'bye']); // bope nye
function processWords(input, arr) {
const counts = {};
let majorityWord = null;
for (const item of arr) {
counts[item] = (counts[item] || 0) + 1;
if (counts[item] >
) {
majorityWord = item;
break;
}
}
if (
) return null;
const processed = `${majorityWord[0]}${input.slice(1)} ${
}${majorityWord.slice(1)}`;
return processed;
}
Type or select from these options