-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpipeFix.js
More file actions
44 lines (31 loc) · 1.03 KB
/
pipeFix.js
File metadata and controls
44 lines (31 loc) · 1.03 KB
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
35
36
37
38
39
40
41
42
43
44
//8 kyu
//Lario and Muigi Pipe Problem
/*
Issue
Looks like some hoodlum plumber and his brother has been running around and damaging your stages again.
The pipes connecting your level's stages together need to be fixed before you receive any more complaints.
The pipes are correct when each pipe after the first is 1 more than the previous one.
Task
Given a list of unique numbers sorted in ascending order, return a new list so that the values increment by 1 for each index from the minimum value up to the maximum value (both included).
Example
Input: 1,3,5,6,7,8 Output: 1,2,3,4,5,6,7,8
*/
//Solution 1
function pipeFix(numbers){
const highest = Math.max(...numbers)
const lowest = Math.min(...numbers)
let newArr = [];
for(let i = lowest; i <= highest; i++){
newArr.push(i)
}
return newArr
}
//Solution 2
function pipeFix2(numbers){
let newArr = [];
for(let i = numbers[0]; i <= numbers[numbers.length - 1]; i++){
newArr.push(i)
}
return newArr
}
console.log(pipeFix2([3,5,7,9]));