-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathp비밀지도.js
43 lines (41 loc) · 1.08 KB
/
p비밀지도.js
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
const toBin = (n, num) => {
let answer = new Array(n).fill(0);
let i = 0;
while (num > 0) {
answer[i] = num % 2;
num = parseInt(num / 2);
i++;
}
answer = answer.map((el) => (el === 0 ? " " : "#"));
// // console.log(answer);
return answer.reverse().join("");
};
// const solution = (n, arr1, arr2) => {
// let answer = [];
// arr1 = arr1.map((el) => toBin(n, el));
// arr2 = arr2.map((el) => toBin(n, el));
// for (let i = 0; i < n; i++) {
// pre = "";
// for (let j = 0; j < n; j++) {
// if (!arr1[i][j] && !arr2[i][j]) {
// pre += " ";
// } else {
// pre += "#";
// }
// }
// // console.log("pre", pre);
// answer.push(pre);
// }
// // console.log(answer);
// return answer;
// };
const solution = (n, arr1, arr2) => {
const answer = [];
for (let i = 0; i < n; i++) {
let pre = arr1[i] | arr2[i];
answer.push(toBin(n, pre));
}
return answer;
};
console.log(solution(5, [9, 20, 28, 18, 11], [30, 1, 21, 17, 28]));
console.log(solution(6, [46, 33, 33, 22, 31, 50], [27, 56, 19, 14, 14, 10]));