CodeWars - Sum of Numbers Function - JavaScript [on hold]












0












$begingroup$


I am passing 108 tests but am failing 4, and can't figure out why:



https://www.codewars.com/kata/55f2b110f61eb01779000053/train/javascript



function GetSum(a, b) {

let lowestNumber = Math.min(a, b);

let highestNumber = Math.max(a, b);

let sum = 0;

if (lowestNumber === highestNumber) {
return 1;
}

else {

for (let i = lowestNumber; i <= highestNumber; i++) {
sum = i + sum;
}

return sum;

}

}


I've established that if a and b are equal, the function should return 1.



So why would the function be returning 1 when it's expecting something else?




Expected: -5, instead got: 1



Expected: 0, instead got: 1



Expected: -17, instead got: 1



Expected: 17, instead got: 1




I thought === meant strictly equal, so why would it expect something else when a and b are strictly equal?










share|improve this question







New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant 3 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1




    $begingroup$
    what should 'GetSum(-1, -1)' return? In your case it would return 1.
    $endgroup$
    – dustytrash
    6 hours ago










  • $begingroup$
    Yes I think it's always supposed to return 1 if the numbers are equal - right?
    $endgroup$
    – HappyHands31
    6 hours ago








  • 2




    $begingroup$
    in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
    $endgroup$
    – Roman
    6 hours ago












  • $begingroup$
    @Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
    $endgroup$
    – HappyHands31
    6 hours ago






  • 1




    $begingroup$
    @HappyHands31 yes, stackoverflow for errors and codereview for working code :]
    $endgroup$
    – Roman
    6 hours ago
















0












$begingroup$


I am passing 108 tests but am failing 4, and can't figure out why:



https://www.codewars.com/kata/55f2b110f61eb01779000053/train/javascript



function GetSum(a, b) {

let lowestNumber = Math.min(a, b);

let highestNumber = Math.max(a, b);

let sum = 0;

if (lowestNumber === highestNumber) {
return 1;
}

else {

for (let i = lowestNumber; i <= highestNumber; i++) {
sum = i + sum;
}

return sum;

}

}


I've established that if a and b are equal, the function should return 1.



So why would the function be returning 1 when it's expecting something else?




Expected: -5, instead got: 1



Expected: 0, instead got: 1



Expected: -17, instead got: 1



Expected: 17, instead got: 1




I thought === meant strictly equal, so why would it expect something else when a and b are strictly equal?










share|improve this question







New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$



put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant 3 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant

If this question can be reworded to fit the rules in the help center, please edit the question.












  • 1




    $begingroup$
    what should 'GetSum(-1, -1)' return? In your case it would return 1.
    $endgroup$
    – dustytrash
    6 hours ago










  • $begingroup$
    Yes I think it's always supposed to return 1 if the numbers are equal - right?
    $endgroup$
    – HappyHands31
    6 hours ago








  • 2




    $begingroup$
    in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
    $endgroup$
    – Roman
    6 hours ago












  • $begingroup$
    @Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
    $endgroup$
    – HappyHands31
    6 hours ago






  • 1




    $begingroup$
    @HappyHands31 yes, stackoverflow for errors and codereview for working code :]
    $endgroup$
    – Roman
    6 hours ago














0












0








0





$begingroup$


I am passing 108 tests but am failing 4, and can't figure out why:



https://www.codewars.com/kata/55f2b110f61eb01779000053/train/javascript



function GetSum(a, b) {

let lowestNumber = Math.min(a, b);

let highestNumber = Math.max(a, b);

let sum = 0;

if (lowestNumber === highestNumber) {
return 1;
}

else {

for (let i = lowestNumber; i <= highestNumber; i++) {
sum = i + sum;
}

return sum;

}

}


I've established that if a and b are equal, the function should return 1.



So why would the function be returning 1 when it's expecting something else?




Expected: -5, instead got: 1



Expected: 0, instead got: 1



Expected: -17, instead got: 1



Expected: 17, instead got: 1




I thought === meant strictly equal, so why would it expect something else when a and b are strictly equal?










share|improve this question







New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







$endgroup$




I am passing 108 tests but am failing 4, and can't figure out why:



https://www.codewars.com/kata/55f2b110f61eb01779000053/train/javascript



function GetSum(a, b) {

let lowestNumber = Math.min(a, b);

let highestNumber = Math.max(a, b);

let sum = 0;

if (lowestNumber === highestNumber) {
return 1;
}

else {

for (let i = lowestNumber; i <= highestNumber; i++) {
sum = i + sum;
}

return sum;

}

}


I've established that if a and b are equal, the function should return 1.



So why would the function be returning 1 when it's expecting something else?




Expected: -5, instead got: 1



Expected: 0, instead got: 1



Expected: -17, instead got: 1



Expected: 17, instead got: 1




I thought === meant strictly equal, so why would it expect something else when a and b are strictly equal?







javascript






share|improve this question







New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question







New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question






New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 7 hours ago









HappyHands31HappyHands31

1042




1042




New contributor




HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






HappyHands31 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant 3 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant

If this question can be reworded to fit the rules in the help center, please edit the question.







put on hold as off-topic by πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant 3 hours ago


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "Code not implemented or not working as intended: Code Review is a community where programmers peer-review your working code to address issues such as security, maintainability, performance, and scalability. We require that the code be working correctly, to the best of the author's knowledge, before proceeding with a review." – πάντα ῥεῖ, Sᴀᴍ Onᴇᴌᴀ, Zeta, vnp, Mike Brant

If this question can be reworded to fit the rules in the help center, please edit the question.








  • 1




    $begingroup$
    what should 'GetSum(-1, -1)' return? In your case it would return 1.
    $endgroup$
    – dustytrash
    6 hours ago










  • $begingroup$
    Yes I think it's always supposed to return 1 if the numbers are equal - right?
    $endgroup$
    – HappyHands31
    6 hours ago








  • 2




    $begingroup$
    in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
    $endgroup$
    – Roman
    6 hours ago












  • $begingroup$
    @Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
    $endgroup$
    – HappyHands31
    6 hours ago






  • 1




    $begingroup$
    @HappyHands31 yes, stackoverflow for errors and codereview for working code :]
    $endgroup$
    – Roman
    6 hours ago














  • 1




    $begingroup$
    what should 'GetSum(-1, -1)' return? In your case it would return 1.
    $endgroup$
    – dustytrash
    6 hours ago










  • $begingroup$
    Yes I think it's always supposed to return 1 if the numbers are equal - right?
    $endgroup$
    – HappyHands31
    6 hours ago








  • 2




    $begingroup$
    in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
    $endgroup$
    – Roman
    6 hours ago












  • $begingroup$
    @Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
    $endgroup$
    – HappyHands31
    6 hours ago






  • 1




    $begingroup$
    @HappyHands31 yes, stackoverflow for errors and codereview for working code :]
    $endgroup$
    – Roman
    6 hours ago








1




1




$begingroup$
what should 'GetSum(-1, -1)' return? In your case it would return 1.
$endgroup$
– dustytrash
6 hours ago




$begingroup$
what should 'GetSum(-1, -1)' return? In your case it would return 1.
$endgroup$
– dustytrash
6 hours ago












$begingroup$
Yes I think it's always supposed to return 1 if the numbers are equal - right?
$endgroup$
– HappyHands31
6 hours ago






$begingroup$
Yes I think it's always supposed to return 1 if the numbers are equal - right?
$endgroup$
– HappyHands31
6 hours ago






2




2




$begingroup$
in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
$endgroup$
– Roman
6 hours ago






$begingroup$
in the instructions is written: If the two numbers are equal return a or b. Instead of 1 return a and it will work.. Additional this question is off-topic because it currently is not working..
$endgroup$
– Roman
6 hours ago














$begingroup$
@Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
$endgroup$
– HappyHands31
6 hours ago




$begingroup$
@Roman Thank you. So this is not the place to post code with errors in it? Would the correct place just be stackoverflow.com?
$endgroup$
– HappyHands31
6 hours ago




1




1




$begingroup$
@HappyHands31 yes, stackoverflow for errors and codereview for working code :]
$endgroup$
– Roman
6 hours ago




$begingroup$
@HappyHands31 yes, stackoverflow for errors and codereview for working code :]
$endgroup$
– Roman
6 hours ago










0






active

oldest

votes

















0






active

oldest

votes








0






active

oldest

votes









active

oldest

votes






active

oldest

votes

Popular posts from this blog

How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

is 'sed' thread safe

How to make a Squid Proxy server?