티스토리 뷰

Regular Expression Based Implementation

String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.replace(new RegExp(search, 'g'), replacement);
};

Split and Join (Functional) Implementation

String.prototype.replaceAll = function(search, replacement) {
    var target = this;
    return target.split(search).join(replacement);
};

The regular expression based implementation is the fastest, with the split and join implementation being 53% slower.

출처 : Stackoverflow
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday