#JavaScript (ES6), 37 33 36 29 bytes
s=>(+!+s[0]+"").repeat(s.length)
-4 bytes thanks to ETHProductions, +3 bytes thanks to ETHProductions (if , -7 bytes thanks to CalculatorFelines
has too many 1
s, ~~s
will overflow JS's number storage)
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
.