@vbarbarosh/node-helpers 1.1.3 → 1.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/array_shuffle.js +24 -0
- package/src/http_put_file.js +1 -1
package/package.json
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shuffles an array using Durstenfeld shuffle algorithm.
|
|
3
|
+
*
|
|
4
|
+
* Note: This function performs shuffle in-place. In order
|
|
5
|
+
* to get a shuffled copy use call slice before calling, e.g.
|
|
6
|
+
* array_shuffle(items.slice()).
|
|
7
|
+
*
|
|
8
|
+
* @param array
|
|
9
|
+
* @returns array
|
|
10
|
+
* @link https://stackoverflow.com/a/6274381/1478566
|
|
11
|
+
* @link https://en.wikipedia.org/wiki/Fisher%E2%80%93Yates_shuffle
|
|
12
|
+
*/
|
|
13
|
+
function array_shuffle(array)
|
|
14
|
+
{
|
|
15
|
+
for (let i = array.length; --i > 0; ) {
|
|
16
|
+
const j = Math.floor(Math.random() * (i + 1));
|
|
17
|
+
const x = array[i];
|
|
18
|
+
array[i] = array[j];
|
|
19
|
+
array[j] = x;
|
|
20
|
+
}
|
|
21
|
+
return array;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default array_shuffle;
|
package/src/http_put_file.js
CHANGED