Notice
Recent Posts
Recent Comments
Link
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Tags
more
Archives
Today
Total
관리 메뉴

조이:)

JS Lv.0 편지 본문

JS Algorithm/Lv.0

JS Lv.0 편지

걍조이 2022. 11. 3. 19:15

내가한 답

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