Skip to content

Commit 00b044c

Browse files
committed
Adding reorder-log-files (ruby, easy).
1 parent 435c3cd commit 00b044c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

easy/reorder-log-files/sub.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# @param {String[]} logs
2+
# @return {String[]}
3+
def reorder_log_files(logs)
4+
alpha_log = []
5+
digit_log = []
6+
logs.each do |log|
7+
_, log1, *_ = log.split(/ /)
8+
if log1 =~ /^[0-9]+$/
9+
digit_log << log
10+
else
11+
alpha_log << log
12+
end
13+
end
14+
15+
alpha_log.sort_by! { |log| ident, log1, *rest = log.split(/ /); [log1, rest, ident] }
16+
alpha_log + digit_log
17+
end
18+
19+
# reorder_log_files(["a1 9 2 3 1","g1 act car","zo4 4 7","ab1 off key dog","a8 act zoo"])
20+
21+
# reorder_log_files(["1 n u", "r 527", "j 893", "6 14", "6 82"]) # => ["1 n u", "r 527", "j 893", "6 14", "6 82"]
22+
# reorder_log_files(["j mo", "5 m w", "g 07", "o 2 0", "t q h"])
23+

0 commit comments

Comments
 (0)