Skip to content

Commit 6999154

Browse files
committed
feat: add new funciton
1 parent 49077d5 commit 6999154

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,3 +139,4 @@ export { mapTransform, mapTransformBack } from './mapTransform'
139139
export { generateKeyObject } from './generateKeyObject'
140140
export { arrayToExcel } from './arrayToExcel'
141141
export { getImageData } from './getImageData'
142+
export { removeRoundSpace } from './removeRoundSpace'

src/removeRoundSpace.ts

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
export function removeRoundSpace(data: number[][]) {
2+
let x = 0
3+
const y: Record<string, number> = {}
4+
const col = data[0].length
5+
const row = data.length
6+
const spliceRows = []
7+
const spliceCols = []
8+
for (let i = 0; i < row; i++) {
9+
for (let j = 0; j < col; j++) {
10+
if (data[i][j] === 0)
11+
x++
12+
if (data[i][j] === 0) {
13+
if (!y[j])
14+
y[j] = 0
15+
y[j]++
16+
}
17+
if ((i === row - 1) && y[j] === row)
18+
spliceCols.push(j)
19+
if (j === col - 1 && x === col)
20+
spliceRows.push(i)
21+
if (j === col - 1)
22+
x = 0
23+
}
24+
}
25+
let start = 0
26+
for (let i = 0; i < spliceRows.length; i++) {
27+
const cur = spliceRows[i]
28+
if (cur === start)
29+
start++
30+
else
31+
break
32+
}
33+
let end = spliceRows[spliceRows.length - 1]
34+
for (let i = spliceRows.length; i > start; i--) {
35+
const cur = spliceRows[i - 1]
36+
if (cur === end)
37+
end--
38+
else
39+
break
40+
}
41+
if (end > start)
42+
data.splice(end, spliceRows[spliceRows.length - 1])
43+
data.splice(0, start)
44+
start = 0
45+
for (let i = 0; i < spliceCols.length; i++) {
46+
const cur = spliceCols[i]
47+
if (cur === start)
48+
start++
49+
else break
50+
}
51+
end = spliceCols[spliceCols.length - 1]
52+
for (let i = spliceCols.length; i > start; i--) {
53+
const cur = spliceCols[i - 1]
54+
if (cur === end)
55+
end--
56+
else break
57+
}
58+
for (let i = 0; i < data.length; i++) {
59+
if (end > start)
60+
data[i].splice(end, spliceCols[spliceCols.length - 1])
61+
data[i].splice(0, start)
62+
}
63+
return data
64+
}
65+

0 commit comments

Comments
 (0)