-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistancing.js
More file actions
26 lines (22 loc) · 861 Bytes
/
distancing.js
File metadata and controls
26 lines (22 loc) · 861 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
/*
거리두기 확인하기
P의 상하좌우 확인 후 P의 개수에 따라
O사이 2개이상과 P가 여러 개인 경우를 걸러냄.
*/
function solution(places) {
return places.map(place => place.some((r, ri) =>
r.split('').some((c, ci, arr) => {
if (c === 'X') return false;
const userCount = [ // 상하좌우
(place[ri - 1] || '').charAt(ci),
(place[ri + 1] || '').charAt(ci),
arr[ci - 1] || null,
arr[ci + 1] || null,
].filter(v => v === 'P').length;
if((c === 'O' && userCount >= 2) || (c === 'P' && userCount > 0)) {
return true;
}
return false;
})) ? 0 : 1
);
};