MCPcopy Index your code
hub / github.com/josdejong/mathjs / identify

Function identify

src/utils/array.js:573–594  ·  view source on GitHub ↗
(a)

Source from the content-addressed store, hash-verified

571 * @return {Array} An array of objects containing the original value and its identifier
572 */
573export function identify (a) {
574 if (!Array.isArray(a)) {
575 throw new TypeError('Array input expected')
576 }
577
578 if (a.length === 0) {
579 return a
580 }
581
582 const b = []
583 let count = 0
584 b[0] = { value: a[0], identifier: 0 }
585 for (let i = 1; i < a.length; i++) {
586 if (a[i] === a[i - 1]) {
587 count++
588 } else {
589 count = 0
590 }
591 b.push({ value: a[i], identifier: count })
592 }
593 return b
594}
595
596/**
597 * Remove the numeric identifier from the elements

Callers 4

array.test.jsFile · 0.90
setDifference.jsFile · 0.90
setIsSubset.jsFile · 0.90
setIntersect.jsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…