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

incnum

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

incnum - npm Package Compare versions

Comparing version 1.0.0 to 1.0.1

26

index.js

@@ -5,20 +5,8 @@ "use strict";

function next(current, ranges) {
if (ranges.some(x => typeof x === 'number' ? x === 0 : x.end - x.begin === 0)) {
return -1;
}
let cu = current.length - 1;
for (; cu >= 0; cu--) {
const range = ranges[cu];
let begin = 0, end = 0;
if (typeof range === 'number') {
end = range;
if (++current[cu] >= ranges[cu]) {
current[cu] = 0;
}
else {
begin = range.begin;
end = range.end;
}
if (++current[cu] >= end) {
current[cu] = begin;
}
else {
break;

@@ -31,8 +19,8 @@ }

function seq(initial, ranges) {
let prev = initial.concat();
let cur = initial.concat();
if (ranges.some(x => x === 0)) {
return [];
}
const res = [];
while (next(cur, ranges) !== -1) {
res.push(prev);
prev = cur.concat();
for (let current = initial.concat(), cu = 0; cu !== -1; cu = next(current, ranges)) {
res.push(current.concat());
}

@@ -39,0 +27,0 @@ return res;

@@ -1,28 +0,7 @@

export type BeginEnd = {
begin: number;
end: number;
};
export type End = number;
export type Range = BeginEnd | End;
export function next(current: number[], ranges: Range[]) {
if (ranges.some(x => typeof x === 'number' ? x === 0 : x.end - x.begin === 0)) {
return -1;
}
export function next(current: number[], ranges: number[]) {
let cu = current.length - 1;
for (; cu >= 0; cu--) {
const range = ranges[cu];
let begin = 0, end = 0;
if (typeof range === 'number') {
end = range;
if (++current[cu] >= ranges[cu]) {
current[cu] = 0;
} else {
begin = range.begin;
end = range.end;
}
if (++current[cu] >= end) {
current[cu] = begin;
} else {
break;

@@ -34,11 +13,11 @@ }

export function seq(initial: number[], ranges: Range[]) {
let prev = initial.concat();
let cur = initial.concat();
export function seq(initial: number[], ranges: number[]) {
if (ranges.some(x => x === 0)) {
return [];
}
const res = [];
while (next(cur, ranges) !== -1) {
res.push(prev);
prev = cur.concat();
for (let current = initial.concat(), cu = 0; cu !== -1; cu = next(current, ranges)) {
res.push(current.concat());
}
return res;
}
{
"name": "incnum",
"version": "1.0.0",
"version": "1.0.1",
"description": "increment numbers in array. this can make multiple depth for-loop single.",

@@ -5,0 +5,0 @@ "main": "index.js",

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