Last active
October 2, 2019 11:01
-
-
Save ianldgs/63828ec6dfa3cf0667871de2128d4351 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @link https://jsperf.com/javascript-string-character-finder/7 | |
*/ | |
function indexesOf(string, regex) { | |
var match, | |
indexes = {}; | |
regex = new RegExp(regex); | |
while (match = regex.exec(string)) { | |
if (!indexes[match[0]]) indexes[match[0]] = []; | |
indexes[match[0]].push(match.index); | |
} | |
return indexes; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment