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

I am getting a Runtime Error.

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

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

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