Skip to content

Instantly share code, notes, and snippets.

@seanwalsh
Last active September 3, 2015 14:41
Show Gist options
  • Save seanwalsh/2ce55c004275b9671da8 to your computer and use it in GitHub Desktop.
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.
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