Skip to main content
4 of 12
added 57 characters in body
Stephen
  • 14k
  • 3
  • 52
  • 117

#JavaScript (ES6), 37 33 36 29 bytes

s=>(+!+s[0]+"").repeat(s.length)

-4 bytes thanks to ETHProductions, +3 bytes thanks to ETHProductions (if s has too many 1s, ~~s will overflow JS's number storage), -7 bytes thanks to CalculatorFeline

Outputs either "0"s or "1"s. Therefore, the only strings we need to worry about only contain 0s or 1s. ~~s:?"0":"1" converts the string to a number. If that number is 0, show 1s; otherwise, show 0s.

I'm pretty sure that ~~s?"0":"1" can be golfed, but I just can't think of any way right now. It must return a string, because you can't call .repeat on a number, but "0" is true, not false.

Stephen
  • 14k
  • 3
  • 52
  • 117