Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var f = function fun (x, f)
- { var newf="",newn="",result="",aux=[],i=0;
- for(;i<f.length;++i)
- {aux.push(f[i]);}
- f=aux;aux=[];
- for(i=0;i<x.length;++i)
- {aux.push(x[i]);}
- x=aux;
- if(f.indexOf('#')== -1) return f;
- for(i=0;i<f.indexOf('#');i=i+1)
- {result=result+f[i];}
- result=result+x[0];
- for(i=i+1;i<f.length;i=i+1)
- {newf=newf+f[i];}
- for(i=1;i<x.length;i=i+1)
- {newn=newn+x[i];}
- return result+fun(newn,newf);}
- function test (implementation, testcases) {
- for ( const {input, output} of testcases ) {
- const result = implementation(...input);
- if (result === output) {
- console.log("-> SUCCESS");
- } else {
- console.log(`-> FAILURE : expected ${JSON.stringify(output)} but got ${JSON.stringify(result)}`);
- }
- }
- }
- const testcases = [
- {
- input: ['1234567890', '(###) ###-####'],
- output: '(123) 456-7890',
- },
- {
- input: ['07123456789', '##### ######'],
- output: '07123 456789',
- },
- {
- input: ['01189998819991197253', '#### ### ### ### ### ### #'],
- output: '0118 999 881 999 119 725 3',
- },
- ];
- test(f, testcases);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement