-
Notifications
You must be signed in to change notification settings - Fork 325
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
refactor: smaller package size #50
Conversation
Codecov ReportBase: 96.82% // Head: 94.87% // Decreases project coverage by
Additional details and impacted files@@ Coverage Diff @@
## master #50 +/- ##
==========================================
- Coverage 96.82% 94.87% -1.96%
==========================================
Files 1 1
Lines 63 78 +15
Branches 13 13
==========================================
+ Hits 61 74 +13
- Misses 2 4 +2
Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here. ☔ View full report at Codecov. |
src/index.ts
Outdated
others.forEach((num) => { | ||
res = operation(res, num); | ||
}); | ||
for (let i = 1, len = nums.length; i < len; ++i) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea very much, better to use array#reduce:
let [first, ...others] = numbers;
return others.reduce((prev, next) => operation(prev, next), first) as number;
在这个 PR 中我做了一些改进,以及一些自作主张的调整。
首先关于第一点,我实施它是因为可以使得压缩 gzip 后包变得更小了:
之前:
之后:
同时在效率上能够有微弱的提升:
在 Chrome 下运行数次,递归方案平均时长约在 242ms,循环方案时长约在 235ms,不过这个性能差异在正常的使用中我觉得几乎没影响。
第二点是我自作主张的调整,我认为全面的参数说明和英语能够更广泛的适应更多用户,如果你不喜欢这样的调整,我可以撤回。