Last active
September 3, 2015 14:41
-
-
Save seanwalsh/2ce55c004275b9671da8 to your computer and use it in GitHub Desktop.
Based off of https://www.briandunning.com/cf/391. Added comments to help a developer understand recursive functions.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Let( | |
[ | |
NumbersOnly = Filter ( Phone; "0123456789" ); // make sure we are only dealing with numerals | |
NewNumber = Right ( NumbersOnly; Length ( NumbersOnly ) - 1 ); // trim the string by 1 for the next recursive call | |
NewFormat = Right ( Format; Length ( Format ) - 1 ) // trim the string by 1 for the next recursive call | |
]; | |
Case ( | |
not IsEmpty ( Format ); // This allows the function to exit. | |
Case ( | |
// if the first character is a pound/hash | |
Left ( Format; 1 ) = "#"; Left ( NumbersOnly; 1 ) & PhoneFormat ( NewNumber; NewFormat ); | |
// else process normally | |
Left ( Format; 1 ) & PhoneFormat ( NumbersOnly; NewFormat ) | |
) // end case | |
) | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment