JavaScript Mini

编程入门 行业动态 更新时间:2024-10-07 22:25:43
本文介绍了JavaScript Mini-Max Sum-HackerRank网站的挑战的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

这是挑战:

www.hackerrank/challenges/mini-max-sum/problem

尽管我的回答是相同的符合预期结果的数字,我做错了某件事,因为我的答案被拒绝了。 我该如何解决?

Despite my answer is returning the same number that matches the expected result, I have done something wrong because my answer has been rejected. How can I solve it?

这是我尝试过的解决方案:

Here is the solution I had tried:

function miniMaxSum(arr) { var arrClone1 = arr.slice() var arrClone2 = arr.slice() var arrMinor = arrClone1.sort(function(a, b){return a - b;}) arrMinor.pop() var arrMajor = arrClone2.sort(function(a, b){return b - a;}) arrMajor.pop() function getSum(a, b) { return a + b; } var result1 = arrMinor.reduce(getSum) var result2 = arrMajor.reduce(getSum) console.log(`${result1} ${result2}`) // it is returning: 10 14

推荐答案

我找到了答案。我注意到将函数参数命名为输入而不是 arr是强制性的。这就是为什么尽管代码返回了正确的结果,答案仍被HackerRank平台拒绝的原因

I found the answer. I noticed that was mandatory to name the function argument as 'input' instead of 'arr'. That's why the answer was rejected by the HackerRank platform despite the code returned the right result

就像这样

function miniMaxSum(input) { //'input' not 'arr' var arrClone1 = input.slice() //'input' not 'arr' var arrClone2 = input.slice() //'input' not 'arr' //... rest of the code omitted

更多推荐

JavaScript Mini

本文发布于:2023-11-30 18:43:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1651111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JavaScript   Mini

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!