The Office III - Broken Photocopier
CodeWars ๋งํฌ ์คํผ์ค 3ํ ์ ๋์ด๋๊ฐ ๋ฎ์์ง๋๊ฐ.. :disappointed:
๋ฌธ์
The bloody photocopier is broken... Just as you were sneaking around the office to print off your favourite binary code! Instead of copying the original, it reverses it: '1' becomes '0' and vice versa. Given a string of binary, return the version the photocopier gives you as a string.
๋ฌธ์ ์ดํด
ํผ๋ฌป์(?) ๋ณต์ฌ๊ธฐ๊ฐ ๊ณ ์ฅ๋ฌ๋๋ฐ.. ๋ณต์ฌ๋ฅผ ํ๋ฉด 0 -> 1๋ก 1 -> 0์ผ๋ก ๋๋ค.
Sample Tests
function broken (x) {}
assertSimilar(broken("1"), "0");
assertSimilar(broken("10000000101101111110011001000"), "01111111010010000001100110111");
assertSimilar(broken("100010"), "011101");ํด๊ฒฐ ๋ฐฉ๋ฒ
๋งค๊ฐ๋ณ์๋ฅผ String.prototype.split()์ ์ด์ฉํด string์ ๋ฐฐ์ด๋ก ๋ง๋ ๋ค.
๋ฐฐ์ด์ด ๋ x๋ฅผ Array.prototype.map()์ ์ฌ์ฉํด ์์ ํ๋ํ๋์ ์ ๊ทผํ์ฌ 0 -> 1, 1 -> 0์ผ๋ก
๋ฐ๊ฟ ์๋ก์ด ๋ฐฐ์ด์ return ํ๋ค.
Array.prototype.join()์ผ๋ก string์ผ๋ก returnํ๋ค.
์ฝ๋ ๊ตฌํ
๊ฒฐ๊ณผ ๋ถ์
๋๋ค ํ ์คํธ ํต๊ณผ
@mordoss, user5036852, jsheng1996's Solution
์์ ๋ด ์์ค์์
๊ฐ ์์ฌ์ ๋๋ฐ ์ด ๋ถ๋ถ์
์ด๋ ๊ฒ arrow ํจ์์ ํ์ค return์ผ๋ก ์ฌ์ฉํ ๊ป ์์ฌ์์ด ๋จ๋๋ค.
Last updated
Was this helpful?