[level 0] 접미사인지 확인하기

2025. 6. 11. 14:36·Daily Logs/Algorithm Practice

function solution(my_string, is_suffix) {
    return my_string.endsWith(is_suffix) ? 1 : 0;
}
  • 주요 문법 : String.prototype.endsWith()

String 값의 endsWith() 메서드는 문자열이 이 문자열의 문자로 끝나는지 여부를 결정하여 적절하게 true 또는 false를 반환합니다.

 

String.prototype.endsWith() - JavaScript | MDN

String 값의 endsWith() 메서드는 문자열이 이 문자열의 문자로 끝나는지 여부를 결정하여 적절하게 true 또는 false를 반환합니다.

developer.mozilla.org

const str1 = "Cats are the best!";

console.log(str1.endsWith("best!"));
// Expected output: true

console.log(str1.endsWith("best", 17));
// Expected output: true

const str2 = "Is this a question?";

console.log(str2.endsWith("question"));
// Expected output: false 

/*
searchString
str 끝에서 검색할 문자. 정규 표현식이 될 수 없습니다. 정규식이 아닌 모든 값은 [문자열로 강제 변환]되므로 이를 생략하거나 undefined를 전달하면 endsWith()가 "undefined" 문자열을 검색하게 되는데, 이는 원하는 경우가 거의 없습니다.

endPosition Optional
searchString이 발견될 것으로 예상되는 끝 위치(searchString의 마지막 문자의 인덱스에 1을 더한 값)입니다. 기본값은 str.length입니다.

반환 값
searchString이 빈 문자열인 경우를 포함하여 문자열 끝에 주어진 문자가 있으면 **true**를 반환하고, 그렇지 않으면 **false**를 반환합니다.
*/

 

'Daily Logs > Algorithm Practice' 카테고리의 다른 글

[Lv 0 QR code]  (0) 2025.06.13
[level 0] 접두사인지 확인하기  (1) 2025.06.12
[level 0] 접미사 배열  (1) 2025.06.09
[level 0] 세로 읽기  (0) 2025.06.08
LV 0 문자열 뒤집기  (0) 2025.06.07
'Daily Logs/Algorithm Practice' 카테고리의 다른 글
  • [Lv 0 QR code]
  • [level 0] 접두사인지 확인하기
  • [level 0] 접미사 배열
  • [level 0] 세로 읽기
Jcob.moon
Jcob.moon
반가워요~ 하루하루 꾸준히 코딩 작성하는 곳입니다 !!
  • Jcob.moon
    Pixelated Thoughts
    Jcob.moon
  • 전체
    오늘
    어제
    • HelloWorld (178)
      • Daily Logs (126)
        • TIL (Today I Learned) (65)
        • Algorithm Practice (55)
        • Dev Book Notes (6)
      • Deep Dives (36)
        • 문제 해결 (Troubleshooting) (3)
        • CS Fundamentals (22)
        • Career Prep (4)
        • Technical Notes (7)
      • Project Log (7)
      • Any (3)
      • Cooperation (5)
        • Github (2)
        • Conventions (1)
        • Git (1)
        • Postman (1)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 최근 댓글

  • hELLO· Designed By정상우.v4.10.3
Jcob.moon
[level 0] 접미사인지 확인하기
상단으로

티스토리툴바