Runtime Error :(

Can you help me please to optimize this code:

function breakingRecords(scores) {
  var arr1 = scores.filter((i, d) => d !== 0 ? Math.max(...scores.slice(0, d)) < i: i).length;
  var arr2 = scores.filter((i, d) => d !== 0 ? Math.min(...scores.slice(0, d)) > i: i).length;
  return (arr1 - 1).toString() + " " + (arr2 - 1).toString();
}

What are you trying to do with the code? To you have some sample inputs and outputs?

sample input: [10, 5, 20, 20, 4, 5, 2, 25, 1]
sample output: 2 4

You titled your topic “Runtime Error”. What error are you getting?

I am getting a Runtime Error.

Right, but a Runtime Error contains more information. What is the full error?

The instructions state for you to return an array with two elements. Is your function doing that?

Yes, It does that. I am sure the problem is the time of execution

Not according to the code you posted above. You might want to validate the type of data you are returning.

Can you validate what I last stated?

I used multiple types of data as outputs such as string and integer … but It still doesn’t work

The above line returns a string, but the instructions state to return an array with 2 elements. Those two elements should be integers. First get your function’s return value to be what is expected, then we can work on the logic of your algorithm.

2 Likes