Advertisement
Guest User

badcode#31

a guest
Feb 27th, 2020
252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. var f = function fun (x, f)
  3. {   var newf="",newn="",result="",aux=[],i=0;
  4.     for(;i<f.length;++i)
  5.     {aux.push(f[i]);}
  6.     f=aux;aux=[];
  7.     for(i=0;i<x.length;++i)
  8.     {aux.push(x[i]);}
  9.     x=aux;
  10.     if(f.indexOf('#')== -1) return f;
  11.     for(i=0;i<f.indexOf('#');i=i+1)
  12.     {result=result+f[i];}
  13.     result=result+x[0];
  14.     for(i=i+1;i<f.length;i=i+1)
  15.     {newf=newf+f[i];}
  16.     for(i=1;i<x.length;i=i+1)
  17.     {newn=newn+x[i];}
  18.     return result+fun(newn,newf);}
  19.  
  20.  
  21. function test (implementation, testcases) {
  22.     for ( const {input, output} of testcases ) {
  23.         const result = implementation(...input);
  24.         if (result === output) {
  25.             console.log("-> SUCCESS");
  26.         } else {
  27.             console.log(`-> FAILURE : expected ${JSON.stringify(output)} but got ${JSON.stringify(result)}`);
  28.         }
  29.     }
  30. }
  31.  
  32. const testcases = [
  33.     {
  34.         input: ['1234567890', '(###) ###-####'],
  35.         output: '(123) 456-7890',
  36.     },
  37.     {
  38.         input: ['07123456789', '##### ######'],
  39.         output: '07123 456789',
  40.     },
  41.     {
  42.         input: ['01189998819991197253', '#### ### ### ### ### ### #'],
  43.         output: '0118 999 881 999 119 725 3',
  44.     },
  45. ];
  46.  
  47. test(f, testcases);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement