We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fe61a93 commit 682c4bbCopy full SHA for 682c4bb
level-2/거리두기-확인하기.js
@@ -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