Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/jssm/jssm_util.d.ts>find_repeated

Fast, easy Javascript finite state machines with visualizations; enjoy a one liner FSM instead of pages. MIT; Typescripted; 100% test coverage. Implements the FSL language.
Go to Latest
function find_repeated
import { find_repeated } from "https://deno.land/x/jssm@5.99.0/jssm_util.d.ts";

Lists all repeated items in an array along with their counts. Subject to matching rules of Map. NaN is manually removed because of conflict rules around unique. Because these are compared with === and because arrays and objects never match that way unless they're the same object, arrays and objects are never considered repeats.

find_repeated<string>([ ]);                     // []
find_repeated<string>([ "one" ]);               // []
find_repeated<string>([ "one", "two" ]);        // []
find_repeated<string>([ "one", "one" ]);        // [ ["one", 2] ]
find_repeated<string>([ "one", "two", "one" ]); // [ ["one", 2] ]
find_repeated<number>([ 0, NaN, 0, NaN ]);      // [ [0,     2] ]

Returns

[T, number][]