{"id":22881499,"url":"https://github.com/luludotdev/weighted-array","last_synced_at":"2025-10-13T22:02:10.825Z","repository":{"id":31542364,"uuid":"128236961","full_name":"luludotdev/weighted-array","owner":"luludotdev","description":"Select a random element from a weighted array.","archived":false,"fork":false,"pushed_at":"2023-01-04T21:43:09.000Z","size":1100,"stargazers_count":0,"open_issues_count":8,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-05-02T04:09:48.026Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"isc","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/luludotdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-04-05T16:57:06.000Z","updated_at":"2021-03-30T16:29:08.000Z","dependencies_parsed_at":"2023-01-14T19:16:50.396Z","dependency_job_id":null,"html_url":"https://github.com/luludotdev/weighted-array","commit_stats":null,"previous_names":["luludotdev/weighted-array","lolpants/weighted-array"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luludotdev%2Fweighted-array","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luludotdev%2Fweighted-array/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luludotdev%2Fweighted-array/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/luludotdev%2Fweighted-array/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/luludotdev","download_url":"https://codeload.github.com/luludotdev/weighted-array/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246491685,"owners_count":20786241,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-13T17:37:31.551Z","updated_at":"2025-10-13T22:02:05.750Z","avatar_url":"https://github.com/luludotdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 🎲 Weighted Map\n[![NPM version](https://img.shields.io/npm/v/weighted-map.svg?maxAge=3600)](https://www.npmjs.com/package/weighted-map)\n[![NPM downloads](https://img.shields.io/npm/dt/weighted-map.svg?maxAge=3600)](https://www.npmjs.com/package/weighted-map)\n[![Build status](https://travis-ci.org/lolPants/weighted-array.svg)](https://travis-ci.org/lolPants/weighted-array)\n[![Dependencies](https://img.shields.io/david/lolpants/weighted-array.svg?maxAge=3600)](https://david-dm.org/lolpants/weighted-array)\n[![Coverage Status](https://coveralls.io/repos/github/lolPants/weighted-array/badge.svg?branch=master)](https://coveralls.io/github/lolPants/weighted-array?branch=master)\n\n##### Select a random element from a weighted array.\n\n## 💾 Installation\nThe package is on the NPM registry as `weighted-map`. Simply install it with your NPM client of choice.\n\n## 🔧 Usage\nFirst, import the module:\n```js\nconst weightedMap = require('weighted-map')\n```\n\nThe `select()` function takes a Map. Maps should be of type `Map\u003cT, number\u003e` where key `T` is your object, and value `number` is the relative weight for that key.\n\nThere is also the `selectUnique*()` ES6 generator which will return randomly but without sequential repeats.\n\nBoth return one object from the array, with the whole object intact.\n\n### 📝 Example\n```js\n// Import the module\nconst { select } = require('weighted-map')\n\nconst map = new Map()\n  .set('ben', 1)\n  .set('jerry', 2)\n\nconsole.log(select(map)) // -\u003e Will return 'jerry' twice as often as 'ben'\n```\n\n## ❤ Thanks\n* [weighted-random](https://www.npmjs.com/package/weighted-random)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluludotdev%2Fweighted-array","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fluludotdev%2Fweighted-array","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fluludotdev%2Fweighted-array/lists"}