알고리즘
[프로그래머스/카카오 블라인드] 비밀지도
limew
2023. 6. 6. 16:11
https://school.programmers.co.kr/learn/courses/30/lessons/17681
- 0,0 일때 빼고 다 1이다 => OR | 를 이용해서 두 십진법의 OR bit연산을 구한다
- 이진법으로 변환 toString(2)
- regex /0|1/g
- 0|1: 0 or 1
- g 전체를 찾음
- replace(변경할 문자 찾는 규칙, 찾은 문자를 변경하는 규칙)
- +string : number 타입으로 변환
function solution(n, arr1, arr2) {
return arr1.map((v, i) => addZero(n, (v | arr2[i]).toString(2)).replace(/1|0/g, a => +a ? '#' : ' '));
}
const addZero = (n, s) => {
return '0'.repeat(n - s.length) + s;
}