-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjs120876.js
More file actions
21 lines (18 loc) · 756 Bytes
/
js120876.js
File metadata and controls
21 lines (18 loc) · 756 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const solution = (lines) => {
let count = lines.map(data=>Math.abs((data[0])-(data[1])));
let lineArr = lines.reduce((result,data,lineIndex)=>[...result,
...Array(count[lineIndex]).fill(data[0]).map((num,index)=>num+index)],[]);
let set = [...new Set(lineArr)]
return set.reduce((result,num)=>check(num)?++result:result,0);
function check(number){
let countNum = 0;
lineArr.forEach(numberData => {
if(number==numberData) ++countNum;
});
return countNum>=2;
}
}
console.log(solution([[0, 2], [-3, -1], [-2, 1]]));
console.log(solution([[0, 1], [2, 5], [3, 9]]));
console.log(solution([[-1, 1], [1, 3], [3, 9]]));
console.log(solution([[0, 5], [3, 9], [1, 10]]));