[Codewars] Moves in squared strings (II)
n 라인의 문자열을 180도, 360도 회전시키는 문제
예시:
[code language=”javascript”]
|rotation |selfie_and_rot
|abcd –> ponm |abcd –> abcd….
|efgh lkji |efgh efgh….
|ijkl hgfe |ijkl ijkl….
|mnop dcba |mnop mnop….
….ponm
….lkji
….hgfe
….dcba”
[/code]
[code language=”javascript”]
function rot(s) {
return s.split(“”).reverse().join(“”);
}
function selfieAndRot(s) {
return (s = s.replace(/.+/g, t => t + t.replace(/./g, “.”))) + “\n” + rot(s);
}
[/code]