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.
use for loop and compare a digit
condition:array[i]<array[i-1]
note :this sort only one time
solution:use while loop outside
sort method first convert into string than it short like
1122 is less than 25 because it only compare first
It is considered a bad practice to modify the input arrays, but in the great majority of katas it won't be a problem if you do it. The rare cases where it is a problem are in general badly designed katas and should be fixed.
Could you provide more informations: language, what's the problem exactly and how you fixed it exactly?
That function iterates through the array, and compares two elements at a time. Those two elements are
a
andb
. Ifa - b
is negative, then we know thata
is smaller thanb
, and thereforea
should appear in the sorted array beforeb
. Ifa-b
is positive, we know thatb
must be smaller and appear in the sorted array earlier thana
. That's the basics of how it works. You could achieve the same result with something like:The custom function inside
Array.sort()
is just looking for a positive, negative, or 0 return value and it uses those to arrange the elements accordingly.Use it properly. Read the documentation of your language. Also read this: https://docs.codewars.com/training/troubleshooting/
This comment is hidden because it contains spoiler information about the solution
^
is the operator for a bitwise XOR.In fact, C# doesn't have an operator for exponentiation :)
You forgot
using System;
to useMath.Pow
try to use "^" sign insted of Math.Pow in C#
I get this eror: "src/Solution.cs(11,36): error CS0103: The name 'Math' does not exist in the current context"
but I think c# has Math fuction. and I use "Math.Pow(x, y)" methode.