指数增长一线功能在一个测试中失败,而其他测试却没有失败?
有人可以为我调试吗?我一直盯着它并测试了几个小时,但似乎无法正常工作。我开始怀疑编码挑战Web应用程序是否错了,我是对的!
任务是:
找到人口
p0
超过最大总体p
的世代数量,鉴于人口增加了>>>>%
%>%加上AUG
每一代
如下:
nbYear = (p0, percent, aug, p) => {
return Array(999).fill().filter((_,i)=>Array(i+1).fill().map((_,j)=>j==0?p0:0).reduce((y,_)=>Math.round(y*percent/100+y+aug))<=p).length;
}
我编写的代码通过100个测试,但在一个测试中失败(他们没有透露失败的输入参数)。它说的只是该函数给出了输出:51
应该是50
Can anyone debug this for me? I've been staring at it and testing things for hours but can't seem to get it working. I'm starting to wonder whether the coding challenge web app is wrong and I'm right!
The task is this:
Find the number of generations it would take for a population
p0
to surpass a max populationp
given that the population increases bypercent
% plusaug
every generation
My one-liner is as follows:
nbYear = (p0, percent, aug, p) => {
return Array(999).fill().filter((_,i)=>Array(i+1).fill().map((_,j)=>j==0?p0:0).reduce((y,_)=>Math.round(y*percent/100+y+aug))<=p).length;
}
The code I've written passes on 100 tests but fails on one in particular (they don't disclose the input paramters on which it failed). All it says is that the function gave the output: 51
when it should have been 50
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我得出的结论是,失败的一个测试一定是以超过999的价值来进行的。
I've concluded that the one test for which it failed must have been for a value over 999.