curriculum/challenges/english/blocks/daily-coding-challenges-javascript/69a890af247de743333bd4cc.md
Given a 6x6 matrix (array of arrays), representing a QR code, return the string of binary data in the code.
1's (orientation markers) in the bottom-left, top-left, and top-right corners.For example, given:
[
"110011",
"110011",
"000000",
"000000",
"110000",
"110001"
]
or given the same code with a different orientation:
[
"110011",
"110011",
"000000",
"000000",
"000011",
"100011"
]
Return "000000000000000000000001", all the binary data excluding the three 2x2 orientation markers.
decodeQr(["110011", "110011", "000000", "000000", "110000", "110001"]) should return "000000000000000000000001".
assert.equal(decodeQr(["110011", "110011", "000000", "000000", "110000", "110001"]), "000000000000000000000001");
decodeQr(["100011", "000011", "000000", "000000", "110011", "110011"]) should return "000000000000000000000001".
assert.equal(decodeQr(["100011", "000011", "000000", "000000", "110011", "110011"]), "000000000000000000000001");
decodeQr(["110011", "111111", "010000", "110000", "110011", "110100"]) should return "001101000011000000110100".
assert.equal(decodeQr(["110011", "111111", "010000", "110000", "110011", "110100"]), "001101000011000000110100");
decodeQr(["011011", "101011", "101000", "100010", "110011", "111011"]) should return "010001000100010101010110".
assert.equal(decodeQr(["011011", "101011", "101000", "100010", "110011", "111011"]), "010001000100010101010110");
decodeQr(["111100", "110001", "100011", "001101", "110011", "110011"]) should return "010000100100100101001110".
assert.equal(decodeQr(["111100", "110001", "100011", "001101", "110011", "110011"]), "010000100100100101001110");
function decodeQr(qrCode) {
return qrCode;
}
function isOriented(code) {
const markerIndices = [
[0, 0],
[0, 1],
[0, 4],
[0, 5],
[1, 0],
[1, 1],
[1, 4],
[1, 5],
[4, 0],
[4, 1],
[5, 0],
[5, 1]
];
for(const [row, col] of markerIndices) {
if (code[row][col] !== '1') return false;
}
return true;
}
function rotate(code) {
const newCode = ['', '', '', '', '', ''];
for (let i = 0; i < 6; i++) {
for (let j = 5; j >= 0; j--) {
newCode[i] += code[j][i];
}
}
return newCode;
}
function getData(code) {
let data = '';
data += code[0].substring(2, 4)
data += code[1].substring(2, 4)
data += code[2]
data += code[3]
data += code[4].substring(2)
data += code[5].substring(2)
return data;
}
function decodeQr(qrCode) {
let code = [...qrCode];
while(!isOriented(code)) {
code = rotate(code);
}
return getData(code);
}