https://github.com/spencermountain/dirty.js
do questionable things to the js built-in methods
https://github.com/spencermountain/dirty.js
Last synced: about 1 month ago
JSON representation
do questionable things to the js built-in methods
- Host: GitHub
- URL: https://github.com/spencermountain/dirty.js
- Owner: spencermountain
- Created: 2013-02-28T16:07:50.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2015-06-11T17:24:35.000Z (almost 10 years ago)
- Last Synced: 2025-03-08T17:43:16.659Z (about 2 months ago)
- Language: JavaScript
- Homepage:
- Size: 508 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
you're not supposed to, but...
==========================it's all gonna be fine.
```javascript
npm install dirtyjs
```
```javascript
require("dirty")
[1,2,2,3].uniq()
//[1,2,3]
```or in the browser:
````javascript[1,2,3].sum()
// 6````
### Salacious Methods of questionable value
```javascript
var arr=[1,2,2,3]
arr.topk()
//[{"value":"2","count":2},{"value":"1","count":1},{"value":"3","count":1}]
arr.topkp()
//[{"value":"2","count":2,"percentage":0.5},{"value":"1","count":1,"percentage":0.25},{"value":"3","count":1,"percentage":0.25}]
arr.spigot(function(s){return s==2})
//{"true":[2,2]
//"false":[1,3]}
arr.dupes()
//[2]
arr.uniq()
//[1,2,3]
arr.includes(2)
//true
arr.includes(20)
//false
arr.shuffle().length
//arr.length
arr.sum()
//8
arr.average()
//2[1,[2],3].flatten()
//[1,2,3]
[1,2,null,3].compact()
//[1,2,3]
[1,1,1].random()
//1var arr=[{id:1},{id:2},{id:2},{id:3}]
arr.uniq('id')
//[{"id":1},{"id":2},{"id":3}]
arr.pluck('id')
//[1,2,2,3]
arr.average('id')
//2```