hassanzohdy/collection/math-aggregation

Claude Code and agent skill by hassanzohdy/collection

Trust tier 3
  • community
Source check pending

Checking that the SKILL.md file is still in the repository.

Tutorial-style "when to use which math method" guide for `@mongez/collection` — totaling, averaging, finding min/max/median, counting by predicate or by key, applying per-item arithmetic (`plus`/`minus`/`multiply`/`divide`/`modulus`/`increment`/`decrement`/`double`/`half`), parity filters (`even`/`odd`/`evenIndexes`/`oddIndexes`).

Install

npx vskill@latest install hassanzohdy/collection/math-aggregation

SKILL.md

Math & Aggregation

How to use

Aggregate reducers

All four accept an optional key string (dot-notation supported) to operate on a field rather than the item itself.

ts
const nums = collect([10, 20, 30]);
nums.sum(); // 60
nums.average(); // 20
nums.avg(); // 20 (alias)
nums.min(); // 10
nums.max(); // 30
nums.median(); // 20
const orders = collect([
{ total: { price: 100 } },
{ total: { price: 200 } },
]);
orders.sum("total.price"); // 300
orders.average("total.price"); // 150
orders.min("total.price"); // 100
orders.max("total.price"); // 200
count — conditional count
ts
collect(users).count(u => u.active); // number of active users
collect(users).count("active"); // same, using a key string
countValue — exact value occurrences
ts
collect(["a", "b", "a", "c"]).countValue("a"); // 2
countBy — frequency map per key value
ts
collect(users).countBy("role");
// { admin: 3, user: 12, guest: 1 }
Per-item arithmetic — plus, minus, multiply, divide, modulus

Two overloads each:

  1. Primitive items — single amount argument.
  2. Keyed field — (key, amount) arguments; returns a new collection with that field updated on each item.
ts
// Primitive
collect([1, 2, 3]).plus(10); // [11, 12, 13]
collect([10, 20]).multiply(3); // [30, 60]
collect([9, 6]).divide(3); // [3, 2]
collect([10, 7]).modulus(3); // [1, 1]
// Keyed field
collect([{ age: 20 }, { age: 30 }]).plus("age", 5);
// [{ age: 25 }, { age: 35 }]
collect(items).multiply("price", 1.2); // apply 20% markup
increment / decrement — shorthand ±1
ts
collect([1, 2, 3]).increment(); // [2, 3, 4]
collect(items).increment("views"); // views + 1 on each item
collect(items).decrement("stock"); // stock - 1 on each item
double / half — shorthand ×2 and ÷2
ts
collect([5, 10]).double(); // [10, 20]
collect([10, 20]).half(); // [5, 10]
collect(items).double("price");
collect(items).half("discount");
even / odd — filter by numeric value parity
ts
collect([1, 2, 3, 4]).even(); // [2, 4]
collect([1, 2, 3, 4]).odd(); // [1, 3]
collect(items).even("score"); // items where score is even
evenIndexes / oddIndexes — filter by position parity
ts
collect(["a","b","c","d"]).evenIndexes(); // ["a","c"] (indexes 0, 2)
collect(["a","b","c","d"]).oddIndexes(); // ["b","d"] (indexes 1, 3)

Key details / Pitfalls

  • min / max on an empty collection return 0 (matching @mongez/reinforcements convention). On a non-empty collection they find the true minimum/maximum, so a collection of all-positive numbers will not incorrectly return 0 for max.
  • sum, average, and median delegate directly to @mongez/reinforcements' helpers.
  • Keyed arithmetic does not mutate plain-object items. plus("age", 5) shallow-clones each plain-object item via cloneForSet before calling set(clone, key, value), so the originals in the source collection are safe. Class instances and nested object references are still passed through by reference (the clone is shallow) — deep-clone the input first if deep immutability is required.
  • divide throws Error("Cannot divide by zero") and modulus throws Error("Cannot have a modulus of zero") when the divisor is 0.
  • All per-item math methods return a new collection — they do not mutate this.items.

Security

  • Security scanPassed, 90 of 100Pattern checks on the skill's files.
  • Model reviewPassed

Quality evaluation

  • Task evaluationNot runNo evaluation yet. Run one in Skill Studio.

Source

Popularity

7-day trend score
0

Not refreshed yet.

Works with

Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.

  • Claude Code
  • Cursor
  • GitHub Copilot
  • Windsurf
  • Codex
  • Gemini CLI
  • Cline
  • Amp
  • Roo Code
  • Goose
  • Continue
  • Kilo Code
  • Junie
  • Trae
  • OpenHands
  • Qwen Code
  • AI Agent
  • Tabnine Chat
  • Sourcegraph Cody
  • Amazon Q
  • Firebase Genkit
  • Sweep
  • Devin
  • Phind
  • Mentat
  • Claude Desktop
  • Aider
  • GPT Pilot
  • Plandex
  • bolt.new
  • v0
  • Replit Agent
  • Anse
  • TypingMind
  • BetterChatGPT
  • LibreChat
  • Warp AI
  • Pieces
  • Fig AI
Embed badge
vskill VERIFIED badge
[![vskill VERIFIED](https://verified-skill.com/api/v1/skills/hassanzohdy/collection/math-aggregation/badge)](https://verified-skill.com/skills/hassanzohdy/collection/math-aggregation)

Something wrong with this skill or its page? Tell us.