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; |
39
index.ts
@@ -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", |
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
14612
143