Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion target-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,15 @@ function findFruitsStartWith(char) {
}

function findFruitsEndWith(char) {
// 여기를 구현합니다.
var len = fruits.length,
i = 0,
regex = new RegExp(char + '$');

for (; i < len; i++) {
if (regex.test(fruits[i])) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

정규식으로 비교하지 않고, String.prototype.lastIndexOf()로 비교해보면 어떨까요?

jsPerf에서 정규식과 lastIndexOf의 검색 성능을 테스트해보니,
크롬에서는 정규식이, IE에서는 lastIndexOf()가 조금 빠르네요.
비교 집단이 작아서 좀 더 테스트를 해보긴 해야겠습니다.

어디선가 정규식은 굳이 로컬 변수로 설정하지 않아도 내부적으로 캐시 처리를 한다는 아티클을 본 것 같은데,
잘못 본 것이었나 봅니다. 혹시나 해서 테스트해보니, 로컬 변수로 설정해둔 게 양쪽 브라우저에서 다 빠르군요.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request가 들어온 커밋에 대해 위와 같은 방식으로 리뷰를 달아줍니다.

마크다운(markdown) 서식을 쓸 수 있어서 링크나 이미지 등도 쉽게 넣을 수 있습니다.

return fruits[i];
}
}
}

console.log(findFruitsStartWith('c'));
Expand Down