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

just-cartesian-product

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-cartesian-product - npm Package Compare versions

Comparing version 1.0.2 to 3.1.0

index.d.ts

32

index.js

@@ -16,15 +16,13 @@ module.exports = cartesianProduct;

function baseProduct(arr1, arr2) {
var output = [];
function baseProduct(prevProduct, arr2) {
//pre allocate all our memory
var newProduct = new Array(prevProduct.length * arr2.length);
for (var i = 0; i < arr1.length; i++) {
var item = isArray(arr1[i]) ? arr1[i] : [arr1[i]];
for (var i = 0; i < prevProduct.length; i++) {
for (var j = 0; j < arr2.length; j++) {
var items = item.concat([arr2[j]]);
output.push(items);
//always provide array to array.concat for consistent behavior
newProduct[i * arr2.length + j] = prevProduct[i].concat([arr2[j]]);
}
}
return output;
return newProduct;
}

@@ -34,3 +32,3 @@

if (!isArray(arr)) {
throw new Error('just-array-product expects an array');
throw new Error('just-cartesian-product expects an array');
}

@@ -42,9 +40,17 @@

var output = arr[0];
if(!isArray(arr[0])) {
throw new Error('set at index 0 must be an array');
}
//initialize our product array
var product = arr[0].map(function(v) { return [v]; });
for (var i = 1; i < arr.length; i++) {
output = baseProduct(output, arr[i]);
if(!isArray(product)) {
throw new Error('set at index ' + i + ' must be an array');
}
product = baseProduct(product, arr[i]);
}
return output;
return product;
}
{
"name": "just-cartesian-product",
"version": "1.0.2",
"version": "3.1.0",
"description": "Cartesian product of arrays",
"type": "commonjs",
"main": "index.js",
"module": "index.esm.js",
"exports": {
".": {
"require": "./index.js",
"default": "./index.esm.js"
}
},
"types": "index.d.ts",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build": "rollup -c"
},

@@ -9,0 +19,0 @@ "repository": "https://github.com/angus-c/just",

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