MCPcopy Create free account
hub / github.com/TruthHun/BookStack / createIndexFinder

Function createIndexFinder

static/word2md/mammoth.browser.js:28500–28522  ·  view source on GitHub ↗
(dir, predicateFind, sortedIndex)

Source from the content-addressed store, hash-verified

28498
28499 // Generator function to create the indexOf and lastIndexOf functions
28500 function createIndexFinder(dir, predicateFind, sortedIndex) {
28501 return function(array, item, idx) {
28502 var i = 0, length = getLength(array);
28503 if (typeof idx == 'number') {
28504 if (dir > 0) {
28505 i = idx >= 0 ? idx : Math.max(idx + length, i);
28506 } else {
28507 length = idx >= 0 ? Math.min(idx + 1, length) : idx + length + 1;
28508 }
28509 } else if (sortedIndex && idx && length) {
28510 idx = sortedIndex(array, item);
28511 return array[idx] === item ? idx : -1;
28512 }
28513 if (item !== item) {
28514 idx = predicateFind(slice.call(array, i, length), _.isNaN);
28515 return idx >= 0 ? idx + i : -1;
28516 }
28517 for (idx = dir > 0 ? i : length - 1; idx >= 0 && idx < length; idx += dir) {
28518 if (array[idx] === item) return idx;
28519 }
28520 return -1;
28521 };
28522 }
28523
28524 // Return the position of the first occurrence of an item in an array,
28525 // or -1 if the item is not included in the array.

Callers 1

mammoth.browser.jsFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected