-
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbreakingRecords.js
More file actions
32 lines (26 loc) · 653 Bytes
/
breakingRecords.js
File metadata and controls
32 lines (26 loc) · 653 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @link Problem definition [[docs/hackerrank/implementation/breakingRecords.md]]
*/
function breakingRecords(scores) {
if (scores.length === 0) {
throw new Error('Empty input');
}
let min = scores[0];
let max = scores[0];
let i;
const recordsBottom = [];
const recordsTop = [];
for (i = 0; i < scores.length; i++) {
if (scores[i] < min) {
min = scores[i];
recordsBottom.push(scores[i]);
}
if (scores[i] > max) {
max = scores[i];
recordsTop.push(scores[i]);
}
}
return [recordsTop.length, recordsBottom.length];
}
export default { breakingRecords };
export { breakingRecords };