Version 1
Version 2 : refactoring loop logic and creates a specialized function
Version 3 : pure functional