Does anyone know how to write an implementation of a function that sorts an array in the following way:
Given the following array(randomly ordered):
["1.2", "1.5.3", "1.5", "1.5.2", "1.4", "1.5.3.2", "1", "1.1", "1.5.3.1", "1.2.1", "1.3", "1.5.1", "2", "2.2", "2.1", "3.1", "3", "3.2.1", "3.2.2", "3.2", "3.3", "4"]
it should result into ->
["1", "1.1", "1.2", "1.2.1", "1.3", "1.4", "1.5", "1.5.1", "1.5.2", "1.5.3", "1.5.3.1", "1.5.3.2", "2", "2.1", "2.2", "3", "3.1", "3.2", "3.2.1", "3.2.2", "3.3", "4"]
I'm currently trying to do it in JavaScript with .sort(), and not really succeeding. Logic in any language would be greatly appreciated.