Missing letters - Please help with .reduce()

Tell us what’s happening:
Hey, I’ve got two questions:

  1. What’s the difference between Array.prototype.reduce() & TypedArray.prototype.reduce()?
  2. How can I solve this challenge with a

previous value parameter

in my function that I pass into reduce? Thanks

Your code so far

function fearNotLetter(str) {
  var arr=str.split("");
arr.reduce((prevVal, acc, curr, index, arr)=>{
if(arr.charCodeAt(index) % prevVal != 1){
return curr;
} else {
  return undefined;
  return arr;


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36.

Link to the challenge:

There isn’t any in terms of what they do, they work the same way. But a typed array is a fixed length container used for storing and manipulating buffers of binary data (eg raw image/video data), it’s not a general-purpose thing like a normal JS array.

Possibly use an object as the accumulator, something like {previous: undefined, current: undefined, missing: undefined}. Then each item, fill in current/previous. If previous isn’t undefined and the char code of current is 2 greater than that of previous, fill in the missing letter.

1 Like

How would I do that? Are you supposed to make the object the accumulator argument and work from there?

reduce is maybe not the best thing for this, but if you are using it, you can pass anything you like as the accumulator. By default it is the first item in the array, but it can be an object or an array or a string or whatever.

reduce takes an array and changes it into a single value of some other type (whatever the accumulator is) which can be anything.

Another way would be to have the accumulator be the missing letter, so it starts as undefined, and every iteration you use the third and fourth callback arguments (index and the array) to check the previous value against the current one and if it signifies a missing letter, update the accumulator.

At the minute you’ve said it should be a number (you’re starting a 0), which doesn’t make much sense.

1 Like