MCPcopy
hub / github.com/hotoo/pinyin / compact2array

Function compact2array

lib/util.js:54–75  ·  view source on GitHub ↗

* 组合两个拼音数组,形成一个新的二维数组 * @param {string[]|string[][]} arr1 eg: ["hai", "huan"] * @param {Array } arr2 eg: ["qian"] * @returns {string[][]} 组合后的二维数组,eg: [ ["hai", "qian"], ["huan", "qian"] ]

(a1, a2)

Source from the content-addressed store, hash-verified

52 * @returns {string[][]} 组合后的二维数组,eg: [ ["hai", "qian"], ["huan", "qian"] ]
53 */
54function compact2array(a1, a2) {
55 if (!Array.isArray(a1) || !Array.isArray(a2)) {
56 throw new Error("compact2array expect two array as parameters");
57 }
58 if (!a1.length) {
59 a1 = [""];
60 }
61 if (!a2.length) {
62 a2 = [""];
63 }
64 const result = [];
65 for (let i = 0, l = a1.length; i < l; i++) {
66 for (let j = 0, m = a2.length; j < m; j++) {
67 if (Array.isArray(a1[i])) {
68 result.push([...a1[i], a2[j]]);
69 } else {
70 result.push([a1[i], a2[j]]);
71 }
72 }
73 }
74 return result;
75}
76
77function compact(arr) {
78 if (arr.length === 0) {

Callers 1

compactFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…