6 kyu

Sort the number sequence

358 of 930myjinxin2015

Description:

When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said

Description

You are given a number sequence (an array) that contains some positive integer and zero.

[3,2,1,0,5,6,4,0,1,5,3,0,4,2,8,0]

It can be split to some zero-terminated sub sequence, such as [3,2,1,0], [5,6,4,0] ..

Your task is: First, sort each sub sequence according to the ascending order (don't sort the zero, it always at the end); Second, sort all sub sequence according to their sum value (ascending order too).

  • Arguments:

    • sequence: The number sequence.
  • Results & Note:

    • The result is the sorted number sequence.
    • If some sub sequences have the same sum value, sort them according to their original order.

Some Examples

sortSequence([3,2,1,0,5,6,4,0,1,5,3,0,4,2,8,0]) should return
[1,2,3,0,1,3,5,0,2,4,8,0,4,5,6,0]

sortSequence([3,2,1,0,5,6,4,0,1,5,3,0,2,2,2,0]) should return
[1,2,3,0,2,2,2,0,1,3,5,0,4,5,6,0]

sortSequence([2,2,2,0,5,6,4,0,1,5,3,0,3,2,1,0]) should return
[2,2,2,0,1,2,3,0,1,3,5,0,4,5,6,0]
Puzzles
Sorting
Algorithms

Stats:

CreatedOct 31, 2016
PublishedOct 31, 2016
Warriors Trained2799
Total Skips60
Total Code Submissions8961
Total Times Completed930
JavaScript Completions358
Haskell Completions54
Python Completions539
λ Calculus Completions3
Total Stars77
% of votes with a positive feedback rating93% of 194
Total "Very Satisfied" Votes172
Total "Somewhat Satisfied" Votes15
Total "Not Satisfied" Votes7
Total Rank Assessments5
Average Assessed Rank
6 kyu
Highest Assessed Rank
5 kyu
Lowest Assessed Rank
7 kyu
Ad
Contributors
  • myjinxin2015 Avatar
  • smile67 Avatar
  • JohanWiltink Avatar
  • FArekkusu Avatar
  • trashy_incel Avatar
  • user8436785 Avatar
Ad