* Returns the index of the first occurrence of the given slice. * @param {array} array Haystack * @param {array} slice Needle slice elements * @param {number} [fromIndex=0] Index at which to begin searching * @return {number} Index of the first slice occurance or -1 if there is none
(array, slice, fromIndex = 0)
| 153 | * @return {number} Index of the first slice occurance or -1 if there is none |
| 154 | */ |
| 155 | static indexOfSlice (array, slice, fromIndex = 0) { |
| 156 | if (slice.length === 0) { |
| 157 | return -1 |
| 158 | } |
| 159 | let i = -1 |
| 160 | let j = fromIndex - 1 |
| 161 | // Find the next occurrence of the first element |
| 162 | while (i === -1 && (j = array.indexOf(slice[0], j + 1)) !== -1) { |
| 163 | // Compare slice |
| 164 | if (this.isEqual(array.slice(j, j + slice.length), slice)) { |
| 165 | i = j |
| 166 | } |
| 167 | } |
| 168 | return i |
| 169 | } |
| 170 | |
| 171 | /** |
| 172 | * Finds all occurences of the given slice inside a target array and replaces |
no test coverage detected