0.0
No commit activity in last 3 years
No release in over 3 years
Sorts strings containing numbers in a semantic way.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies
 Project Readme

SemanticSort

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.

Installation

gem install semantic_sort

Usage

require 'semantic_sort'

puts ['1', '10', '02'].sort           # => ['02', '1', '10']
puts ['1', '10', '02'].semantic_sort   # => ['1', '02', '10']

Sorting Method

  • 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']

Credit

Copyright (C) Coro365
Licensed under the MIT license.