Intermediate Algorithm Scripting - Missing letters

Tell us what’s happening:
hello there. I’m trying to solve this challenge using .reduce() method.
when trying to push to the accumulator, the console drop me an error:

TypeError: accumulator is undefined

why does it happens?

Your code so far

function fearNotLetter(str) {
  let arr = str.split('').map(char => char.charCodeAt());
  console.log(arr);
  let newArr = arr.reduce((accumulator, currentValue, index, array) => {
    accumulator.push();
  }, [])
}

fearNotLetter("abce");

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge: Intermediate Algorithm Scripting - Missing letters

Link to the challenge:

When your “reduce” returns a new array, you need use return statement as such:

let newArr = strArr.reduce((arr, x) => {
    return [...arr, x] // or  return arr.concat(x)
}, [])

But, you still need some way to solve the challenge.
Happy Coding.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.