[Challenge] Version finder
Posted: Tue Dec 07, 2010 7:16 am
Suppose we have a directory/file structure like this:
/Version/1
/Version/1/1/class.php
/Version/1/2
/Version/1/2/1/class.php
/Version/1/2/3/class.php
/Version/2
/Version/2/0/class.php
/Version/2/3/class.php
/Version/2/3/1/class.php
/Version/2/3/5/class.php
etc.
Task: Create a function (class) that accepts a version number and returns the file path to class.php.
Specs:
[*] $version is formatted as a dot separated string - e.g. 1.4.2
[*] function should return the next lowest version number path
[*] function should throw an Exception if no appropriate versions are found (i.e. the lowest version is higher than the searched one)
Expected results:
[text]1.0.1 => throws Exception
1.1 => /Version/1/1/class.php
1.1.3 => /Version/1/1/class.php
1.2 => /Version/1/1/class.php
1.2.1 => /Version/1/2/1/class.php
1.2.2 => /Version/1/2/1/class.php
1.2.3.5 => /Version/1/2/3/class.php
2 => /Version/2/0/class.php
2.1 => /Version/2/0/class.php
2.4 => /Version/2/3/5/class.php
10 => /Version/2/3/5/class.php[/text]
Good luck!
/Version/1
/Version/1/1/class.php
/Version/1/2
/Version/1/2/1/class.php
/Version/1/2/3/class.php
/Version/2
/Version/2/0/class.php
/Version/2/3/class.php
/Version/2/3/1/class.php
/Version/2/3/5/class.php
etc.
Task: Create a function (class) that accepts a version number and returns the file path to class.php.
Specs:
[*] $version is formatted as a dot separated string - e.g. 1.4.2
[*] function should return the next lowest version number path
[*] function should throw an Exception if no appropriate versions are found (i.e. the lowest version is higher than the searched one)
Expected results:
[text]1.0.1 => throws Exception
1.1 => /Version/1/1/class.php
1.1.3 => /Version/1/1/class.php
1.2 => /Version/1/1/class.php
1.2.1 => /Version/1/2/1/class.php
1.2.2 => /Version/1/2/1/class.php
1.2.3.5 => /Version/1/2/3/class.php
2 => /Version/2/0/class.php
2.1 => /Version/2/0/class.php
2.4 => /Version/2/3/5/class.php
10 => /Version/2/3/5/class.php[/text]
Good luck!