πŸ“„ File detail

utils/array.ts

🧩 .tsπŸ“ 14 linesπŸ’Ύ 364 bytesπŸ“ text
← Back to All Files

🎯 Use case

This file lives under β€œutils/”, which covers cross-cutting helpers (shell, tempfiles, settings, messages, process input, …). On the API surface it exposes intersperse, count, and uniq β€” mainly functions, hooks, or classes.

Generated from folder role, exports, dependency roots, and inline comments β€” not hand-reviewed for every path.

🧠 Inline summary

export function intersperse<A>(as: A[], separator: (index: number) => A): A[] { return as.flatMap((a, i) => (i ? [separator(i), a] : [a])) } export function count<T>(arr: readonly T[], pred: (x: T) => unknown): number {

πŸ“€ Exports (heuristic)

  • intersperse
  • count
  • uniq

πŸ–₯️ Source preview

export function intersperse<A>(as: A[], separator: (index: number) => A): A[] {
  return as.flatMap((a, i) => (i ? [separator(i), a] : [a]))
}

export function count<T>(arr: readonly T[], pred: (x: T) => unknown): number {
  let n = 0
  for (const x of arr) n += +!!pred(x)
  return n
}

export function uniq<T>(xs: Iterable<T>): T[] {
  return [...new Set(xs)]
}