+VALUES (6, 'Coding 3min : Symmetric Sort', 'function sc(a) {}', 'Please do a "Symmetric Sort" with it.', '[{"test":"Test.assertSimilar(sc([1,2,3,4,5,6,7,8,9]), [1,3,5,7,9,8,6,4,2], \"good luck!\");","result":""}]', '[{"test":" const fcode=function(str){ const isChar = function(a) { if(a){ var code = a.toLowerCase().charCodeAt(0) return code >= 97 && code <= 122; } return false; } return str.replace(/ ? | /g, '').split('').filter((a,i,x) => { return a==='' ''?isChar(x[i-1])&&isChar(x[i+1])?true:false:true; }).join(''''); } function an(array){//198 var a=array.slice(); a.sort((x,y)=>x-y) for (var i=0,left=[],right=[];i<a.length;i++){ if (i%2==0) left.push(a[i]) else right.unshift(a[i]) } return left.concat(right); } function rndc(){ return String.fromCharCode(~~(26*Math.random())+97); } function rnds(){ var len= ~~(8*Math.random())+1; for (var i=0,rs=[];i<len;i++) rs[i]=rndword(); return rs.join(\" \"); } function rndarray(){ var len= ~~(35*Math.random())+6; for (var i=0,rs=[];i<len;i++){ rs[i]= ~~(99*Math.random())+1; } return rs; } function rndsx(){ var t=~~(100*Math.random())%3; if (t==0) return rndword(~~(100*Math.random())+4); if (t==1) return rnds(~~(100*Math.random())+4) if (t==2) { var nn= ~~(100*Math.random())+4, a= rnds(nn), b=rndword(nn); for (var i=0,rs=[];i<nn;i++) { var x=~~(100*Math.random())%2; rs[i]= x==1 ? a[i] : b[i]; } return rs.join(\"\"); } } console.log(\"<br><font size=4><b>-------- Basic Test --------</b></font>\") console.log(\"\") Test.assertSimilar(sc([1,2,3,4,5,6,7,8,9]), [1,3,5,7,9,8,6,4,2], \"good luck!\"); Test.assertSimilar(sc([1,1,2,2,3,3,4,4,5]), [1,2,3,4,5,4,3,2,1], \"good luck!\"); Test.assertSimilar(sc([9,8,7,6,5,4,3,2,1]), [1,3,5,7,9,8,6,4,2], \"good luck!\"); Test.assertSimilar(sc([5,4,4,3,3,2,2,1,1]), [1,2,3,4,5,4,3,2,1], \"good luck!\"); Test.assertSimilar(sc([11,2,33,4,55,6]), [2,6,33,55,11,4], \"good luck!\"); Test.assertSimilar(sc([5,12,5,8,33,13]), [5,8,13,33,12,5], \"good luck!\"); //anti-cheat and calc the code length console.log(\"<br><font size=4><b>--------Code length check --------</b></font>\") var limit=120; const fs = require(''fs''); const allcode = fs.readFileSync(''/home/codewarrior/solution.txt'', ''utf8''); var code=fcode(allcode.replace(///.* /g,\"\")); var codelen=code.length; if (codelen<=limit) Test.assertSimilar(\"code length<=\"+limit,\"code length>\"+limit, \"your code length = \"+codelen+\", please try this code in challage version. the simple version only accept the solution which length>\"+limit); else Test.assertSimilar(\"PASS\", \"PASS\", \";-)\"); //end of anti-cheat console.log(\"<br><font size=4><b>--------100 Random Test --------</b></font>\") console.log(\"\") for (var myjinxini=0;myjinxini<100;myjinxini++){ var aa=rndarray(),answer=an(aa); console.log(\"<font color=''#CD7F32''>Test: array=[\"+aa+\"]</font>\",\"\") Test.assertSimilar(sc(aa), answer, \"good luck!\"); } console.log(''<br><font size=4><b>Congratulations, You pass the test!</b></font>'','''') console.log(\"<br><font size=4><b>After you submit your solution, <font color=''yellow''>DON''T FORGET UPVOTE&RANK THIS KATA, THANK YOU!</b></font>\",\"\") ","result":""}]')
0 commit comments