MCPcopy
hub / github.com/Swatinem/rust-cache / sort_and_uniq

Function sort_and_uniq

src/config.ts:439–454  ·  view source on GitHub ↗
(a: string[])

Source from the content-addressed store, hash-verified

437}
438
439function sort_and_uniq(a: string[]) {
440 return a
441 .sort((a, b) => a.localeCompare(b))
442 .reduce((accumulator: string[], currentValue: string) => {
443 const len = accumulator.length;
444 // If accumulator is empty or its last element != currentValue
445 // Since array is already sorted, elements with the same value
446 // are grouped together to be continugous in space.
447 //
448 // If currentValue != last element, then it must be unique.
449 if (len == 0 || accumulator[len - 1].localeCompare(currentValue) != 0) {
450 accumulator.push(currentValue);
451 }
452 return accumulator;
453 }, []);
454}

Callers 1

newMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected