-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest1.js
More file actions
34 lines (28 loc) · 934 Bytes
/
test1.js
File metadata and controls
34 lines (28 loc) · 934 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
33
34
function IDsOfPackages(rideDuration, songDurations)
{
// WRITE YOUR CODE HERE
if (songDurations.length <=2) {
return [];
}
let result = {};
let pairs = [];
let longestSong = 0;
const totalDuration = rideDuration -30;
for (let i =0; i<songDurations.length; i++) {
if(songDurations[i]<=totalDuration) {
if (result[songDurations[i]] !== undefined) {
const longSong = Math.max(songDurations[result[songDurations[i]]], songDurations[i]);
console.log(longSong);
if (longSong > longestSong) {
longestSong = longSong;
pairs[0] = [result[songDurations[i]], i];
}
} else {
result[totalDuration-songDurations[i]] = i;
}
}
}
return pairs[0];
}
const nums = [100,180, 40, 120, 10];
console.log(IDsOfPackages(250, nums));