hamza9
December 7, 2020, 8:32pm
1
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?
hamza9
December 7, 2020, 8:49pm
4
sample input: [10, 5, 20, 20, 4, 5, 2, 25, 1]
sample output: 2 4
hamza9
December 7, 2020, 8:55pm
6
I am getting a Runtime Error.
Right, but a Runtime Error contains more information. What is the full error?
hamza9
December 7, 2020, 9:00pm
10
Yes, It does that. I am sure the problem is the time of execution
hamza9
December 7, 2020, 9:11pm
14
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