UNPKG

@lodestar/beacon-node

Version:

A Typescript implementation of the beacon chain

20 lines 696 B
import { toRootHex } from "@lodestar/utils"; export function computeMostCommonTarget(targets) { if (targets.length === 0) { throw Error("Must provide at least one target"); } const countById = new Map(); let mostCommonTarget = targets[0]; let mostCommonCount = 0; for (const target of targets) { const targetId = `${target.slot}-${toRootHex(target.root)}`; const count = 1 + (countById.get(targetId) ?? 0); countById.set(targetId, count); if (count > mostCommonCount) { mostCommonCount = count; mostCommonTarget = target; } } return mostCommonTarget; } //# sourceMappingURL=chainTarget.js.map