UNPKG

1.46 kBSource Map (JSON)View Raw
1{"version":3,"sources":["iterable/includes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAE5C;;;;;;;;;GASG;AACH,MAAM,UAAU,QAAQ,CAAI,MAAmB,EAAE,aAAgB,EAAE,YAAoB,CAAC;IACtF,IAAI,OAAO,GAAG,SAAS,CAAC;IACxB,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,IAAI,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,EAAE;QACrB,OAAO,GAAG,CAAC,CAAC;KACb;IACD,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE;QACzB,IAAI,CAAC,EAAE,GAAG,OAAO,IAAI,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC,EAAE;YAClD,OAAO,IAAI,CAAC;SACb;KACF;IACD,OAAO,KAAK,CAAC;AACf,CAAC","file":"includes.js","sourcesContent":["import { comparer } from '../util/comparer';\n\n/**\n * Determines whether an itreable includes a certain value among its entries, returning true or false as appropriate.\n *\n * @export\n * @template T The type of elements in the source sequence.\n * @param {Iterable<T>} source The source sequence to search for the item.\n * @param {T} valueToFind The value to search for.\n * @param {number} [fromIndex=0] The position in this iterable at which to begin searching for valueToFind.\n * @returns {boolean} Returns true if the value valueToFind is found within the iterable.\n */\nexport function includes<T>(source: Iterable<T>, searchElement: T, fromIndex: number = 0): boolean {\n let fromIdx = fromIndex;\n let i = 0;\n if (Math.abs(fromIdx)) {\n fromIdx = 0;\n }\n for (const item of source) {\n if (i++ > fromIdx && comparer(item, searchElement)) {\n return true;\n }\n }\n return false;\n}\n"]}
\No newline at end of file