Skip to content

Commit 682c4bb

Browse files
author
gyeong-hyeon-kim
committed
Add 1 solution.
1 parent fe61a93 commit 682c4bb

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

level-2/거리두기-확인하기.js

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
//https://github.com/codeisneverodd/programmers-coding-test
2+
//완벽한 정답이 아닙니다.
3+
function solution(places) {
4+
var answer = [];
5+
answer = places.map(place => {
6+
return place.some((row, rowIndex) =>
7+
row.split('').some((mark, colIndex, rowArr) => {
8+
if (mark === 'X') return false
9+
const countPeopleAround = [
10+
rowArr[colIndex - 1] || '',
11+
rowArr[colIndex + 1] || '',
12+
(place[rowIndex - 1] || '')[colIndex],
13+
(place[rowIndex + 1] || '')[colIndex],
14+
].filter(mark => mark === 'P').length
15+
return (mark === 'P' && countPeopleAround > 0) || (mark === 'O' && countPeopleAround > 1)
16+
})
17+
) ? 0 : 1
18+
})
19+
return answer;
20+
}

0 commit comments

Comments
 (0)