[Pkg-javascript-commits] [node-mess] 01/02: Imported Upstream version 0.1.2
Andrew Kelley
andrewrk-guest at moszumanska.debian.org
Mon Jun 30 14:47:58 UTC 2014
This is an automated email from the git hooks/post-receive script.
andrewrk-guest pushed a commit to branch master
in repository node-mess.
commit 0169f64796490efe8312c163da533401ccd900b4
Author: Andrew Kelley <superjoe30 at gmail.com>
Date: Mon Jun 30 14:46:08 2014 +0000
Imported Upstream version 0.1.2
---
.gitignore | 1 +
README.md | 30 ++++++++++++++++++++++++++++++
index.js | 19 +++++++++++++++++++
package.json | 28 ++++++++++++++++++++++++++++
4 files changed, 78 insertions(+)
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..a09c56d
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+/.idea
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..e803b7b
--- /dev/null
+++ b/README.md
@@ -0,0 +1,30 @@
+mess
+====
+
+Missing shuffle function for arrays in javascript.
+This is [Fisher–Yates shuffle](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle), and it's very fast.
+
+## Installation
+
+```
+npm install mess
+```
+
+## Usage
+
+```javascript
+var mess = require("mess");
+
+console.log(mess([1,2,3,4,5,6,7,8,9,0]));
+// output will be something like:
+// [ 7, 9, 2, 0, 6, 8, 5, 3, 1, 4 ]
+```
+
+## Why mess
+
+Because naming modules is hard and shuffle is already taken.
+
+## Authors
+
+* [Ronald Fisher and Frank Yates](https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle)
+* [People on internet](http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript#6274398)
diff --git a/index.js b/index.js
new file mode 100644
index 0000000..6ab23f8
--- /dev/null
+++ b/index.js
@@ -0,0 +1,19 @@
+(function(module) {
+ // see https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
+ // and http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript#6274398
+ module.exports = function shuffle(array) {
+ var counter = array.length,
+ temp,
+ index;
+
+ while (counter) {
+ index = Math.floor(Math.random() * counter--);
+
+ temp = array[counter];
+ array[counter] = array[index];
+ array[index] = temp;
+ }
+
+ return array;
+ }
+})(module);
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..958d0f9
--- /dev/null
+++ b/package.json
@@ -0,0 +1,28 @@
+{
+ "name": "mess",
+ "version": "0.1.2",
+ "description": "Mess is Fisher–Yates shuffle algorithm implementation for node.js",
+ "main": "index.js",
+ "scripts": {
+ "test": "echo \"Error: no test specified\" && exit 1"
+ },
+ "repository": {
+ "type": "git",
+ "url": "git at github.com:bobrik/node-mess.git"
+ },
+ "keywords": [
+ "mess",
+ "shuffle",
+ "array_shuffle",
+ "random",
+ "fisher",
+ "yates",
+ "array"
+ ],
+ "author": "Ian Babrou <ibobrik at gmail.com> (http://bobrik.name/)",
+ "license": "BSD",
+ "bugs": {
+ "url": "https://github.com/bobrik/node-mess/issues"
+ },
+ "homepage": "https://github.com/bobrik/node-mess"
+}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-mess.git
More information about the Pkg-javascript-commits
mailing list