JavaScript subLength() code challenge. - Solution works, but not accepted

Hi all,
I am working through the JavaScript Practice: Arrays, Loops, Objects, Iterators code challenges, and up to the subLength() question. I’ve looked at priors posts only after I came up with my own solution, but thought it best to start a new one as this is kind of unique to my solution.

My understanding is that there are no constraints on how this solution is to be achieved, and therefore can use things we have learnt up to this point.

The solution I used is somewhat different, to many others that I saw, even the solution given when I finally compared it to the answer.

The problem I am getting when I run the ‘Check Answer’ is the following message ‘Double check your code. It likely has a syntax error.

The problem is I cannot spot the error. When run it returns the expected values. I have tested it with all the checks provided and more. Each time it yields the desired answers.

If someone is able to shed some light on this that would be greatly appreciated.

const reducer = (previousValue, currentValue) => currentValue - previousValue;

function subLength(string, char) {
  strArray = string.split('');
  let index =[];
  for(let i = 0; i < strArray.length; i ++) {
    if(strArray[i] === char) {
      index.push(i);
    }
  }
  if (index.length < 2 || index.length > 2) {
    return 0;
  } else {
    return (index.reduce((reducer), 1));
  }
}
    
console.log(subLength('Saturday', 'a')); // returns 6
console.log(subLength('summer', 'm')); // returns 2
console.log(subLength('digitize', 'i')); // returns 0
console.log(subLength('cheesecake', 'k')); // returns 0