mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2025-01-08 22:37:37 +01:00
20 lines
622 B
JavaScript
20 lines
622 B
JavaScript
//Netburner String helper functions
|
|
|
|
//Searches for every occurence of searchStr within str and returns an array of the indices of
|
|
//all these occurences
|
|
function getIndicesOf(searchStr, str, caseSensitive) {
|
|
var searchStrLen = searchStr.length;
|
|
if (searchStrLen == 0) {
|
|
return [];
|
|
}
|
|
var startIndex = 0, index, indices = [];
|
|
if (!caseSensitive) {
|
|
str = str.toLowerCase();
|
|
searchStr = searchStr.toLowerCase();
|
|
}
|
|
while ((index = str.indexOf(searchStr, startIndex)) > -1) {
|
|
indices.push(index);
|
|
startIndex = index + searchStrLen;
|
|
}
|
|
return indices;
|
|
} |