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์œผ๋กœ ์‚ฌ์šฉํ• ๊ป„ ์•„์‰ฌ์›€์ด ๋‚จ๋Š”๋‹ค.

js ํŒŒ์ผ ๋ฐ”๋กœ๊ฐ€๊ธฐ

Last updated

Was this helpful?