是否有任何更好的编码方法,因为它感觉非常不切实际,并且有很多空间

发布于 2025-02-04 17:35:36 字数 1393 浏览 3 评论 0原文

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

转身泪倾城 2025-02-11 17:35:36

也许您可以避免使用三元运算符重写分配语句:

let rdm = Math.random() * 100
const firstCase = 19.37 / NewData.PriceDivider
const secondCase = 19.37 / 100 / (5.18 / NewData.PriceDivider)

// Handle rdm === 100 here  if (rdm === 100) // do something

Rarity = rdm < firstCase ? Rarities.uncommon : rdm < secondCase ? Rarities.common : Rarities.basic
Embed.addField("Rarity", Rarity, true);
Embed.setColor(rdm < firstCase ? "GREEN" : "GREY");

如果要处理Math.random()=== 1的情况,我认为您应该在此代码块之前对其进行处理。

Maybe you could avoid rewriting the assignment statements by using ternary operator :

let rdm = Math.random() * 100
const firstCase = 19.37 / NewData.PriceDivider
const secondCase = 19.37 / 100 / (5.18 / NewData.PriceDivider)

// Handle rdm === 100 here  if (rdm === 100) // do something

Rarity = rdm < firstCase ? Rarities.uncommon : rdm < secondCase ? Rarities.common : Rarities.basic
Embed.addField("Rarity", Rarity, true);
Embed.setColor(rdm < firstCase ? "GREEN" : "GREY");

If you want to handle the case where Math.random() === 1, I think you should handle it before this code block.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文