Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

新增紧凑输出方法 #306

Merged
merged 7 commits into from
Dec 16, 2021
Merged

新增紧凑输出方法 #306

merged 7 commits into from
Dec 16, 2021

Conversation

ultravires
Copy link
Contributor

@ultravires ultravires commented Nov 19, 2021

✨ 新增紧凑输出

使用方法

pinyin("还钱", { 
  style: pinyin.STYLE_NORMAL, 
  segment: true, 
  group: true, 
  heteronym: true,
}).compact();
// output: [['huan', 'qian'], ['hai', 'qian']]

const py = pinyin("还钱", { 
  style: pinyin.STYLE_NORMAL, 
  segment: true, 
  group: true, 
  heteronym: true,
});
pinyin.compact(py)

// output: [['huan', 'qian'], ['hai', 'qian']]

@ultravires ultravires changed the title Dev/compact 新增紧凑输出方法 Nov 19, 2021
lib/util.js Show resolved Hide resolved
lib/util.js Outdated Show resolved Hide resolved
let result = compact2array(arr[0], arr[1]);
for (let i = 2, l = arr.length; i < l; i++) {
result = compact2array(result, arr[i]);
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let i = 0;
let result = [];
while (i < arr.length) {
  result = compact2array(result, arr[i]);
  i++;
}

lib/util.js Outdated
}
for (let i = 0, l = a1.length; i < l; i++) {
for (let j = 0, m = a2.length; j < m; j++) {
result.push(a1[i] + "," + a2[j]);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里应该有更好的算法,再想想。

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修改了,你看看

@hotoo
Copy link
Owner

hotoo commented Nov 22, 2021

CI 为什么少了很多用例?

@ultravires
Copy link
Contributor Author

CI 为什么少了很多用例?

没有少吧,先前由于你的 util 测试不通过,我把你的注释了,后来给你注释去掉了(不过错误没给你改)

@@ -39,11 +39,56 @@ function combo(arr) {
return arr[0];
}
let result = combo2array(arr[0], arr[1]);
for (let i = 2, l = arr.length; i < l; i++) {
for (let i = 2, l = arr.length; i < l; ++i) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在这里 i++ 和 ++i 应该是没有区别的。

throw new Error("compact2array expect two array as parameters");
}
if (!a1.length) {
a1 = [undefined];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

为什么要加 undefined ?我怎么感觉代码越改越奇怪了呢?

@hotoo
Copy link
Owner

hotoo commented Nov 22, 2021

没有少吧,先前由于你的 util 测试不通过,我把你的注释了,后来给你注释去掉了(不过错误没给你改)

少了的,你看看 master 分支的单测用例。

@ultravires
Copy link
Contributor Author

没有少吧,先前由于你的 util 测试不通过,我把你的注释了,后来给你注释去掉了(不过错误没给你改)

少了的,你看看 master 分支的单测用例。

嗯嗯。对不起,修复了

@hotoo hotoo merged commit 72ec94e into hotoo:master Dec 16, 2021
@ultravires ultravires deleted the dev/compact branch March 2, 2022 08:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants