spiral-matrix
Advanced tools
Comparing version 0.1.0 to 0.1.1
20
index.js
@@ -15,3 +15,3 @@ /** | ||
} | ||
return arr; | ||
@@ -32,6 +32,17 @@ } | ||
function deepConcat(matrix1, matrix2) { | ||
return [ matrix1[0].concat(matrix2[0]) ]; | ||
} | ||
function spiral(rows, cols, start) { | ||
return rows ? [range(start, start + cols - 1)].concat( | ||
transpose(spiral(cols, rows - 1, start + cols)).map(reverse) | ||
) : [[]]; | ||
if (!rows || !cols) return [[]]; | ||
const curr = [ range(start, start + cols - 1) ]; | ||
const inner = transpose(spiral(cols, rows - 1, start + cols)); | ||
if (inner[0].length === curr[0].length) { | ||
return curr.concat(inner.map(reverse)); | ||
} else { | ||
return deepConcat(curr, inner); | ||
} | ||
} | ||
@@ -41,2 +52,3 @@ | ||
constructor(rows, cols, start) { | ||
start = start || 0; | ||
this._matrix = spiral(rows, cols, start); | ||
@@ -43,0 +55,0 @@ } |
{ | ||
"name": "spiral-matrix", | ||
"version": "0.1.0", | ||
"version": "0.1.1", | ||
"description": "Generate a spiral matrix.", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"test": "node test" | ||
}, | ||
@@ -9,0 +9,0 @@ "repository": { |
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
5809
6
117
1