' + -- + - + - '
' + --- + - + '
' + -- + - + - '
' + - + - + - + '
해(1)와 달(0), Code의 세상안으로! (En-Coding).
출력조건 : 문자열
let result = '';
let arr =
[' + -- + - + - ',
' + --- + - + ',
' + -- + - + - ',
' + - + - + - + '];
for(let elements of arr) {
let binary = elements.replace(/ /g, '').replace(/\+/g, '1').replace(/-/g, '0');
let decimal = parseInt(binary, 2);
result += String.fromCharCode(decimal);
}
사용된 메소드 :
replace() : 특정 패턴에 일치하는 문자열을 교체. 정규 표현식 사용하여 전역으로 교체하기.
parseInt(string, radix) : 문자열을 parse해서 정수로 변환.
radix: indicates that the number in the string should be parsed from a specified radix to a decimal number.
String.fromCharCode() :
returns a string created from 'UTF-16 Code Unit'
ex) String.fromCharCode(65, 66, 67) returns "ABC"