{"id":11618,"library":"quickselect","title":"Quickselect","description":"quickselect is a highly optimized, tiny JavaScript library implementing the Floyd-Rivest selection algorithm. It efficiently partially sorts an array in-place, ensuring that elements up to a specified index `k` are the smallest in the given range. The current stable version is 3.0.0, which was a significant update dropping CommonJS and UMD builds, making it exclusively ESM and requiring modern ES syntax. Releases appear to be infrequent, driven by significant architectural changes or feature additions. Its primary differentiator is its minimal footprint and speed for selection tasks compared to full sorting algorithms, making it ideal for scenarios where only a subset of sorted elements is needed.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/mourner/quickselect","tags":["javascript","selection","algorithm","quickselect","sort","partial","floyd","rivest","typescript"],"install":[{"cmd":"npm install quickselect","lang":"bash","label":"npm"},{"cmd":"yarn add quickselect","lang":"bash","label":"yarn"},{"cmd":"pnpm add quickselect","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package is ESM-only since v3.0.0, meaning CommonJS `require()` is no longer supported.","wrong":"const quickselect = require('quickselect');","symbol":"quickselect","correct":"import quickselect from 'quickselect';"}],"quickstart":{"code":"import quickselect from 'quickselect';\n\nconst arr = [65, 28, 59, 33, 21, 56, 22, 95, 50, 12, 90, 53, 28, 77, 39];\n\n// Rearrange the array such that elements up to index 8 are the smallest.\n// The 8th element (0-indexed) will be the (8 - 0 + 1)th smallest value in the original array.\nquickselect(arr, 8);\n\nconsole.log(arr);\n// Expected output similar to: [39, 28, 28, 33, 21, 12, 22, 50, 53, 56, 59, 65, 90, 77, 95]\n// Note: The order of elements *before* k is not guaranteed, only that they are smaller than or equal to arr[k].\n","lang":"typescript","description":"This example demonstrates how to use `quickselect` to partially sort an array in-place, ensuring that elements up to a specific index `k` are the smallest in the given range."},"warnings":[{"fix":"Migrate your project to use ES modules or ensure your build configuration transpiles `quickselect` as an ES module. Use `import quickselect from 'quickselect';`.","message":"Version 3.0.0 dropped UMD build and full support for CommonJS, making the package ESM-only.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Ensure your build process (e.g., Babel) includes `quickselect` in transpilation if targeting environments that do not fully support modern JavaScript.","message":"Version 3.0.0 uses modern ES syntax, which may break compatibility with older environments (e.g., IE11) without transpilation.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Upgrade to `v2.0.0` or later, which correctly reintroduced the `module` field and resolved previous Webpack compatibility problems.","message":"Version 1.1.1 had issues with some Webpack builds due to the `module` field in `package.json`, which was later rectified.","severity":"gotcha","affected_versions":"1.1.1"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Switch to ES module import syntax: `import quickselect from 'quickselect';`.","cause":"Attempting to use CommonJS `require()` to import `quickselect` version 3.0.0 or later in an ESM environment.","error":"ReferenceError: require is not defined"},{"fix":"Ensure your runtime environment supports modern JavaScript or configure your build pipeline (e.g., Babel, esbuild) to transpile `quickselect`.","cause":"Running `quickselect` v3.0.0+ in an environment that does not fully support modern ES syntax without proper transpilation.","error":"SyntaxError: Unexpected token '...' (related to modern JavaScript features)"}],"ecosystem":"npm"}