문자열을 받아서 공백이 제거된 원래 문자열의 모든 문자를 사용하여 새 문자열을 반환하는 JavaScript 함수를 작성해야 합니다.
예시
이에 대한 코드는 -
const str = "This is an example string from which all whitespaces will be
removed";
const removeWhitespaces = str => {
let newStr = '';
for(let i = 0; i < str.length; i++){
if(str[i] !== " "){
newStr += str[i];
}else{
newStr += '';
};
};
return newStr;
};
console.log(removeWhitespaces(str)); 출력
콘솔의 출력 -
Thisisanexamplestringfromwhichallwhitespaceswillberemoved