Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

randomise-array

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

randomise-array - npm Package Compare versions

Comparing version 1.0.1 to 1.0.3

README.md

2

package.json
{
"name": "randomise-array",
"version": "1.0.1",
"version": "1.0.3",
"description": "Randomise arrays and generate a new array with any given length",

@@ -5,0 +5,0 @@ "main": "randomise-array.js",

@@ -0,4 +1,4 @@

function randomArray(arr, options= {}){
//First perform type checks
// return arr
if (typeof options !== "object") {

@@ -15,21 +15,28 @@ return new Error('The second argument must be an object')

options.length = options.length || arr.length
options.gte = options.gte || -Infinity
options.lte = options.lte || Infinity
if (typeof options.lte !== 'number') {
if (typeof options.lte !== 'number' && typeof options.lte !== 'undefined') {
return new Error('lte must be a number')
}
if (typeof options.gte !== 'number') {
if (typeof options.gte !== 'number' && typeof options.lte !== 'undefined') {
return new Error('gte must be a number')
}
var arr = arr.filter((val) => {
return val >= options.gte && val <= options.lte
})
if (options.lte) {
arr = arr.filter((val) => {
return val <= options.lte
})
}
if (options.gte) {
arr = arr.filter((val) => {
return val >= options.lte
})
}
if(options.length > arr.length && options.unique) {
return new Error(`Cannot generate ${options.length} unique values from ${arr.length} values`)
}
for (currInd = 0; currInd < options.length; currInd++) {
randInd= Math.floor(Math.random()* arr.length)
newArr[currInd] = arr[randInd]
newArr[currInd] = arr[randInd]
if (options.unique) {

@@ -41,2 +48,3 @@ arr.splice(randInd,1)

}
module.exports= exports = randomArray
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc