use-loop-for-min-max-instead-of-sort

Find array minimum and maximum values with a single-pass loop.

Updated Feb 10, 2026
One-click install
npx skills add https://github.com/ihj04982/my-cursor-settings --skill use-loop-for-min-max-instead-of-sort
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: use-loop-for-min-max-instead-of-sort
Source: https://github.com/ihj04982/my-cursor-settings/tree/main/skills/use-loop-for-min-max-instead-of-sort
Command: npx skills add https://github.com/ihj04982/my-cursor-settings --skill use-loop-for-min-max-instead-of-sort

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill addresses the inefficiency of using sorting algorithms to find minimum or maximum values in a dataset, which is computationally more expensive than necessary.

Core Features & Use Cases

  • Efficient Min/Max Finding: Demonstrates how to find the smallest or largest element in an array using a single pass (O(n) complexity).
  • Avoids Unnecessary Sorting: Contrasts the efficient loop-based approach with slower sorting-based methods (O(n log n)).
  • Use Case: When processing a list of user activities to find the most recently updated record, a single loop is faster than sorting the entire list.

Quick Start

Use the use-loop-for-min-max-instead-of-sort skill to find the latest project from a list of projects.

Frequently Asked Questions about use-loop-for-min-max-instead-of-sort

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I find the minimum or maximum value in a TypeScript array without sorting?

Finding the minimum or maximum value in a TypeScript array without sorting is efficiently done using a single-pass loop. This approach scans the array once to identify extreme values, reducing complexity from O(n log n) to O(n) for performance-critical code.

Why does sorting an array just to get the min or max value hurt performance?

Sorting an array just to get the min or max value hurts performance because it carries an O(n log n) complexity overhead. A single-pass loop finds extreme values in O(n) time, making it significantly faster for performance-critical sections.

What is the best way to get the newest or oldest item from time-series data?

The best way to get the newest or oldest item from time-series data is using a single-pass loop. It efficiently checks each record once to find the extreme timestamp, reliably returning the oldest or newest item without sorting the entire series.

When should I use a loop instead of sorting to find extreme values?

You should use a loop instead of sorting to find extreme values when working in performance-critical code sections where only the minimum or maximum element is needed. This avoids the O(n log n) overhead of sorting and processes the array in O(n) time.

Does finding min and max values in a single loop work for large arrays?

Finding min and max values in a single loop works efficiently for large arrays. By iterating through the dataset once, it maintains O(n) complexity, which is optimal for processing large lists of user activities or time-series records.