Got FATAL ERROR on a coding challenge

I need help to improve my solution. I got FATAL ERROR in a coding challenge in codewars site. That is mean my solution is not working with big inputs like:

overTheRoad(23633656673,310027696726);

My code so far:

function overTheRoad(address, n) {
  let odd = [];
  let even = [];
  for (let i = 2; i <= n * 2; i += 2) {
    even.push(i);
  }
  for (let i = 1; i <= n * 2; i += 2) {
    odd.push(i);
  }
  even = even.reverse();

  return address % 2 === 0
    ? odd[even.indexOf(address)]
    : even[odd.indexOf(address)];
}

LINK TO THE CHALLENGE :point_down::

As the challenge description states, building up huge arrays isn’t the solution. Instead, take pen and paper and draw the street for small cases like n=3 or n=4 and look for a pattern. Math is your friend here. You can solve this kata in one short line.

Do you know/have tips for that?

I’m trying to avoid blurting out the solution, so apologies if I’m vague… Look closely at these lines of houses facing each other. They have something in common, one thing is the same for all of them:

1   8
-----
3   6
-----
5   4
-----
7   2

If you find out what they have in common, you can use that to calculate the value of the opposing house for every possible address.

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