[자바스크립트/알고리즘] 특정 문자열로 끝나는지 확인 / 정규식, endsWith() 이용
알고리즘/FreeCodeCamp 2021. 1. 18. 23:07

문제 특정 문자열로 끝나면 true, 아니면 false 반환 나의 풀이 입력: "dogs, cats, and ducks", "ducks" 결과: true function confirmEnding(str, target) { let result = new RegExp(target+"$","i"); return result.test(str); } confirmEnding("dogs, cats, and ducks", "ducks"); 간단하게 endsWith()로 문제를 해결할 수도 있다. [endsWith()] 입력과 결과는 위와 동일하다. 사용방법 function confirmEnding(str, target) { return str.endsWith(target); } (문제 출처:www.freecodeca..