#69  Weight for weight


My friend John and I are members of the "Fat to Fit Club (FFC)". John is worried because each month a list with the weights of members is published and each month he is the last on the list which means he is the heaviest.


I am the one who establishes the list so I told him: "Don't worry any more, I will modify the order of the list". It was decided to attribute a "weight" to numbers. The weight of a number will be from now on the sum of its digits.


For example 99 will have "weight" 18, 100 will have "weight" 1 so in the list 100 will come before 99. Given a string with the weights of FFC members in normal order can you give this string ordered by "weights" of these numbers?


Example:

"56 65 74 100 99 68 86 180 90" ordered by numbers weights becomes: "100 180 90 56 65 74 68 86 99"


When two numbers have the same "weight", let us class them as if they were strings and not numbers: 100 is before 180 because its "weight" (1) is less than the one of 180 (9) and 180 is before 90 since, having the same "weight" (9) it comes before as a string.


All numbers in the list are positive numbers and the list can be empty.




#46 Your order, please



Your task is to sort a given string. Each word in the String will contain a single number. This number is the position the word should have in the result.


Note: Numbers can be from 1 to 9. So 1 will be the first word (not 0).


If the input String is empty, return an empty String. The words in the input String will only contain valid consecutive numbers.


For an input: "is2 Thi1s T4est 3a" the function should return "Thi1s is2 3a T4est"


your_order("is2 Thi1s T4est 3a")


[1] "Thi1s is2 3a T4est"



# Sort the odd


You have an array of numbers.

Your task is to sort ascending odd numbers but even numbers must be on their places.


Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it.


Example


sortArray([5, 3, 2, 8, 1, 4]) == [1, 3, 2, 8, 5, 4]



+ Recent posts