【问题标题】:If there is too many 9s after a certain point do something如果某个点之后有太多的 9 做某事
【发布时间】:2021-11-13 02:40:31
【问题描述】:

所以基本上数学 js 存在一个问题,其中 id 它必须执行这个等式 1:999 或更多的九它会崩溃。

        try
        {
            if(args == "1:999") return message.channel.send('That question is not allowed');

        } catch(error){
            message.channel.send("there was an error")
        }

现在,如果您计算 1:999,它会给出错误,但我希望它查看等式是否还有更多的 9。例如,如果我做了 1:9999999,它也会给出一个错误,但基本上这个等式中超过三个 9 的任何东西都会给出一个错误。

【问题讨论】:

    标签: javascript discord.js mathjs


    【解决方案1】:

    以下示例显示了一个 regular expression 用于测试字符串是否为“1:999”、“1:9999”、“1:99999”、...形式的字符串。

    if (/^1:999+$/.test(arg)) {
    

    【讨论】:

    • 感谢您的帮助,我是 JavaScript 新手,从不知道它的存在。我会投票,但我没有足够的“声誉”
    【解决方案2】:

    您可以使用String#EndsWith 来检查字符串是否以您想要使用String#repeat9 的编号结尾

    if (args.endsWith('9'.repeat(count))) {
      console.log("Too many nines");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-26
      相关资源
      最近更新 更多