如果在某一点之后有太多的9,做一些事情



基本上math js有一个问题,它必须做这个等式1:99或更多的9,它会崩溃。

try
{
if(args == "1:999") return message.channel.send('That question is not allowed');
} catch(error){
message.channel.send("there was an error")
}

现在,如果你让它计算1:99,它会给出一个错误,但我想让它看看方程是否有更多的9。例如,如果我用1:9999999,它也会给出一个错误,但基本上在这个方程中任何超过三个9的都将给出一个错误。

下面的示例显示了一个正则表达式,用于测试字符串是否为"1:999", "1:999", "1:999",…

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

您可以使用String#EndsWith来检查字符串是否以您想要使用String#repeat9的数量结束

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