Loading collection data...
Collections are a way for you to organize kata so that you can create your own training routines. Every collection you create is public and automatically sharable with other warriors. After you have added a few kata to a collection you and others can train on the kata contained within the collection.
Get started now by creating a new collection.
Length of an array is a public final int, so no calculation is done.
see here
http://docs.oracle.com/javase/specs/jls/se7/html/jls-10.html#jls-10.7
really?learn it!
That is not true.
i<length
and
i<arr.length
have exactly the same cost.
The difference would be, when comparing to collection size, such as ArrayList and using .size() method, but here it doesn't matter.
for (int i=0; i<arr.length; i++)
Calculate the length in the cycle, is not efficient
int sum = 0;
int length = arr.length;
for (int i=0; i<length; i++) {
sum += (i % 2 == 0) ? arr[i] : arr[i] * arr[i];
}
return sum;
yes it works on the test cases. It actually passed on the RandomTest.
It does. It works for the example test cases, and for the random tests when I submit.
Hi. Is the solution now available for this problem?
What should be returned when this value was entered "59544965313"? (JAVA)
I can't see any basic tests with only "59544965313" in the input string. I just tried the Java tests with a Codewarrior's Java solution taken at random and it worked fine. Does your solution work for "Your example test cases"?
After coming back to this kata, I'm now stuck at exactly the same point.
When running in eclipse, my method orderedWeights("59544965313") simply returns "59544965313".
Is it not supposed to do that ? I pass the other test(s). It basically does exactly what is supposed to do.
Same issue. Java.
BasicTests(WeightSortTest)
****** Basic Tests ******
For input string: "59544965313"
RandomTests(WeightSortTest)
****** Random tests ******
Test Passed
1 Passed
1 Failed
0 Errors
Process took 3125ms to completeBasicTests(WeightSortTest)
Awesome help, the sort integer thing is something I've seen on here in other people's code but not understood until your reference. Thanks once again for the great advice :)
The false is not the problem.
When you return false, you are giving the correct answer instead of the other wrong stuff.
When you give a correct answer, you move on to the next batch of tests which is where your code fails.
The major bug in the code is here
Always use
var i
. As of now, you are modifying the global variable i.I actually can't believe that the test code is making the same mistake and using a global
i
instead of avar i
.As a result, your function and the test code are messing with each other. I am not really sure how exactly the submission timeout error is occuring, but this mutual interaction is definitely the cause.
Also, the
sort
function by default uses string sort, even if the arguments are numbers.So,
[9, 100, 20, 25]
will get sorted as[100, 20, 25, 9]
instead of[9, 20, 25, 100]
.Sometimes this difference in sorting won't matter. Sometimes it will.
How to sort an array of integers correctly
Please which language?
I didn't catch that this was supposed to be a joke, sorry for misinterpreting you there.
In your citation you are forgetting the
:-)
. I wanted this sentence to be a joke, maybe a bad joke. If somebody finds it as insulting or condescending I am very sorry and I apologize.Loading more items...