Skip to content

Conversation

@jrieken
Copy link
Member

@jrieken jrieken commented Nov 10, 2025

No description provided.

Copilot AI review requested due to automatic review settings November 10, 2025 08:36
@jrieken jrieken enabled auto-merge (squash) November 10, 2025 08:36
@jrieken jrieken self-assigned this Nov 10, 2025
@vs-code-engineering vs-code-engineering bot added this to the November 2025 milestone Nov 10, 2025
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds JSDoc documentation to the quickSelect function in the arrays utility module, improving code discoverability and understanding for developers using this algorithm.

  • Added comprehensive JSDoc comment block explaining the quickselect algorithm and its parameters

* @param data The unsorted array
* @param compare A comparator function that defines the sort order
* @returns The nth smallest element
* @throws TypeError if nth is >= data.length
Copy link

Copilot AI Nov 10, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The @throws documentation is incomplete. The function also needs to handle the case where nth is negative. Looking at line 124, nth = nth | 0; will convert negative values to negative integers, which when compared at line 126 with nth >= data.length won't throw an error, but will likely cause incorrect behavior in the recursive calls. The documentation should clarify the valid range for nth (i.e., 0 <= nth < data.length) or the function should validate negative values.

See below for a potential fix:

 * @throws TypeError if nth is negative or nth is >= data.length
 */
export function quickSelect<T>(nth: number, data: T[], compare: Compare<T>): T {

	nth = nth | 0;

	if (nth < 0 || nth >= data.length) {

Copilot uses AI. Check for mistakes.
@jrieken jrieken merged commit d3d9a1e into main Nov 10, 2025
33 of 34 checks passed
@jrieken jrieken deleted the joh/smooth-jellyfish branch November 10, 2025 08:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants