Comparing version 2.10.0 to 2.11.0
{ | ||
"name": "rjs", | ||
"version": "2.10.0", | ||
"version": "2.11.0", | ||
"description": "A library of Javascript utility functions with an emphasis on Functional Programming.", | ||
@@ -14,3 +14,3 @@ "main": "rjs.js", | ||
"type": "git", | ||
"url": "git://github.com/RaineOrShine/rjs.git" | ||
"url": "git://github.com/metaraine/rjs.git" | ||
}, | ||
@@ -17,0 +17,0 @@ "keywords": [ |
43
rjs.js
/** | ||
* Raine's Javascript Extensions | ||
* v2.9.0 | ||
* v2.11.0 | ||
* A library of Javascript utility functions with an emphasis on Functional Programming. | ||
@@ -461,2 +461,39 @@ */ | ||
/** Returns a new array with the array's items in random order. */ | ||
var randomize = function(arr) { | ||
var output = arr.slice(); | ||
function swap(i,j) { | ||
var temp = output[i]; | ||
output[i] = output[j]; | ||
output[j] = temp; | ||
} | ||
for(var i=0, len=output.length; i<len; i++) { | ||
var r = Math.floor(Math.random() * len); | ||
swap(i, r); | ||
} | ||
return output; | ||
} | ||
/** Breaks up the array into n evenly-sized chunks. */ | ||
var chunk = function(arr, n) { | ||
var output = []; | ||
var len = arr.length; | ||
var bigSize = Math.ceil(len/n); | ||
var smallSize = bigSize - 1; | ||
var rem = len % n; | ||
var size = bigSize; | ||
for(var i=0; i<len; i+=size) { | ||
if(rem > 0 && i >= rem * bigSize) { | ||
size = smallSize; | ||
} | ||
output.push(arr.slice(i, i+size)); | ||
} | ||
return output; | ||
} | ||
/*********************************** | ||
@@ -775,3 +812,3 @@ * Object | ||
install(Number, rjs, ['ordinal', { mapNumber: 'map' }]); | ||
install(Array, rjs, ['map', 'each', 'pluck', 'group', 'orderedGroup', 'tally', 'contains', 'strictContains', 'unique', 'reversed', 'index', 'rotate', 'toObject', 'find', 'findByProperty', 'filterBy', 'any', 'all', 'spliced' ]); | ||
install(Array, rjs, ['map', 'each', 'pluck', 'group', 'orderedGroup', 'tally', 'contains', 'strictContains', 'unique', 'reversed', 'index', 'rotate', 'toObject', 'find', 'findByProperty', 'filterBy', 'any', 'all', 'spliced', 'randomize', 'chunk' ]); | ||
install(Function, rjs, ['curryAt', 'curry', 'rcurry', 'arritize', 'currify', 'toInstance', 'new']); | ||
@@ -837,2 +874,4 @@ return rjs; | ||
filterBy : filterBy, | ||
randomize : randomize, | ||
chunk : chunk, | ||
@@ -839,0 +878,0 @@ // object |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
610731
37
15306