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

代码过于冗余 #8

Open
huluoyang opened this issue Jun 3, 2019 · 1 comment
Open

代码过于冗余 #8

huluoyang opened this issue Jun 3, 2019 · 1 comment

Comments

@huluoyang
Copy link

huluoyang commented Jun 3, 2019

return transformFunc(temp);

关于数组的排序你写了3个函数: transformFunc、_isLargerThan、_comparator 来实现,代码互相缠绕,实在过于冗余。
其实只需一行即可:

let sortedValue = cardList.map(card => card.value).sort((a,b)=>b-a);
@huluoyang
Copy link
Author

huluoyang commented Jun 3, 2019

德州扑克中花色是平级的,所以不应该在花色部分着墨过多,只需关注是否同花即可。
value 部分是显示给用户看的,也不应该过于关注。
代码中最重要的是比大小,所以应该用 value 对应的 number。
所以上面的代码应该修改成:

cardList.map(card => card.number).sort((a,b)=>b-a);

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

No branches or pull requests

1 participant