# Range extraction: convert a comma separated list of integers into range format
def solution(list)
list.chunk_while {|i, j| i+1 == j }.map do |a|
if a.size > 2
a.first.to_s + "-" + a.last.to_s
else
a
end
end.join(',')
end
Code Example |
---|
Ruby :: devise remove * sign up form |
Ruby :: time loop start with non zero in ruby |
Ruby :: rails do something for 3 minutes |
Ruby :: devise manually sign out user |
Ruby :: ruby hash merge vs merge! |
Ruby :: ruby decode base64 |
Ruby :: rails callback STI |
Ruby :: ruby array join |
R :: add a vertical line in ggplot |
R :: r count number of na |
R :: remove elements from character vector in r |
R :: how to read number of excel sheet in r |
R :: convert boolean to int R |
R :: merge multiple datatable in r |
R :: r print concatenate |
R :: chi square critical value in r |
R :: nls in r |
R :: ggplot_regression_line |
R :: how to convert numeric to date in r |
R :: r matrix |
R :: r as.numeric all columns except |
R :: order barplot ggplot2 by value |
R :: knn accuracy in r |
R :: switch to another line in string r |
R :: R construct a named list |
R :: dplyr to vector |
R :: base R change axis line width |
R :: how to get the r2 value in r |
Rust :: rust string to char array |
Rust :: how to open a file rust |