Sorts strings containing numbers in a semantic way.
This gem was created to practice gem creation.
We recommend the following mainstream gems that have the same functionality.
Created based on my gist.
gem install semantic_sort
require 'semantic_sort'
puts ['1', '10', '02'].sort # => ['02', '1', '10']
puts ['1', '10', '02'].semantic_sort # => ['1', '02', '10']
- Start
- ['003.txt', '02.txt', '1.txt']
- Append 0 to the left to match the maximum length of the number sequence
- ['003.txt', '002.txt', '001.txt']
- Sort
- ['001.txt', '002.txt', '003.txt']
- Delete unnecessary zeros
- ['1.txt', '02.txt', '003.txt']
Copyright (C) Coro365
Licensed under the MIT license.