Socket
Socket
Sign inDemoInstall

kth-smallest

Package Overview
Dependencies
3
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    kth-smallest

Find kth smallest element in an array of numbers in amortized linear time


Version published
Weekly downloads
4
Maintainers
1
Install size
38.1 kB
Created
Weekly downloads
 

Readme

Source

kth-smallest

Find kth smallest element in an arary of numbers

Uses a randomized quickselect to achieve O(n) average case time complexity

Build Status

Install

$ npm install kth-smallest

Usage

import kthSmallest from 'kth-smallest'

kthSmallest([10, 20, 30, 40], 0)
// 10

kthSmallest([10, 20, 30, 40], 2)
// 30

kthSmallest([10, 20, 30, 40], -1)
// 40

API

kthSmallest :: number a => [a] -> integer -> a

kthSmallest(numbers, k)

Arguments

  • numbers - An array of numbers
  • k - 0-indexed target (pass negative numbers for largest)

FAQs

Last updated on 07 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc