We're a place where coders share, stay up-to-date and grow their careers.
codesandbox.io/embed/daily-challen...
const iterative = (input: number[], schema: string = "(###) ###-####") => { let result = schema; input.forEach(number => (result = result.replace("#", String(number)))); return result; }; const recursive = ( input: number[], schema: string = "(###) ###-####", result: string = schema ): string => { const [head, ...rest] = input; if (head === undefined) return result; return recursive(rest, schema, result.replace("#", String(head)`)); }; export const createPhoneNumber = { iterative, recursive };
codesandbox.io/embed/daily-challen...