조이:)
JS Lv.0 편지 본문
내가한 답
function solution(message) {
var answer = 0;
let leng = message.length;
if(leng >=1 && leng <=50) answer = leng*2;
return answer;
}
🍔 알고가기
const solution = (message) => {
return message.split('').length * 2
}
split() 사용하기
Note: 빈 문자열이 주어졌을 경우 split()은 빈 배열이 아니라 빈 문자열을 포함한 배열을 반환합니다. 문자열과 separator가 모두 빈 문자열일 때는 빈 배열을 반환합니다.
https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/String/split
String.prototype.split() - JavaScript | MDN
split() 메서드는 String 객체를 지정한 구분자를 이용하여 여러 개의 문자열로 나눕니다.
developer.mozilla.org
function solution(message) {
let arr = String(message).split("");
return arr.length *2;
}
function solution(message) {
var horizontal = null;
if((typeof message)=="string" ){
horizontal = message.length * 2;
}
return horizontal;
}
function solution(message) {
let n =([...(''+message)]);
return n.length*2
}
'JS Algorithm > Lv.0' 카테고리의 다른 글
JS Lv.0 배열 원소의 길이 (0) | 2022.11.03 |
---|---|
JS Lv.0 배열 뒤집기 (0) | 2022.11.03 |
JS Lv.0 짝수 홀수 개수 (0) | 2022.11.02 |
JS Lv.0 피자 나눠 먹기 (1) (0) | 2022.11.02 |
JS Lv.0 머쓱이보다 키 큰 사람 (0) | 2022.11.02 |
Comments