随记01

/*
    javascript版stringformat,带小小格式功能.
    Usage:
        FormatString("{0} {1}");
        FormatString("{0:4} {1:-4}");
*/
function FormatString(string) {
      function RepeatTimes(time,char){return new Array(time+1).join(char);}
      var _args=arguments, length=_args.length; for(var i=1; i< _args[i].getFullYear(),(_args[i].getMonth() _args[i]="Function" Date) instanceof if(_args[i] ?object?: case ; ?undefined?: ?function?: _args[i]) switch(typeof len2; len1="RegExp.$2," var reg.test(string); ?gi?); ?(:((-)?\\d*))?\\}?, - +(i RegExp(?\\{? reg="new" i++){var> 0 && len2 < len1) { _args[i] += RepeatTimes(len1 - len2, " "); } else if(len1 < 0) { _args[i]=RepeatTimes((-len1) - len2, " ") + _args[i]; } } string=string.replace(reg, function() { return _args[i]; }); } return string;
  }
变位词

var words='uta,ust,ute,uva,vai,ure,urd,urf,urn,uro,urs,use,ush,ups,ura,ume,ule,udo,uds,ugh,tua,tub,tug,tue,tun,tup,tur,twa,twi,two,tye,tib,tic,tid,tho,tig,til,tin,tip,tis,toa,tod,tog,toi,tol,tom,ton,too,top,tor,tou,tow,toy,tra,tri,taa,tab,sye,tae,tag,tai,taj,tal,tam,tan,tao,tap,tar,tau,tav,taw,tay,tea,teg,ten,tew,tha,the,vat,vau,vee,vei,via,vie,sri,ssi,ssu,sob,soc,sod,soe,soh,sog,sok,son,spa,stu,sub,sud,sue,sum,sup,sur,sus,swa,sia,sib,sid,shu,sil,sim,she,shi,sho,sin,sip,sir,sis,sit,sla,sly,sma,sea,sat,saw,say,seg,sen,ser,sew,sey,sha,saa,sab,rut,rye,run,rus,sad,sag,sah,sai,sak,sal,sam,sap,sar,rit,rim,rio,rip,rob,roc,rod,roe,rog,roi,rok,ron,rot,row,roy,rua,rub,rud,rue,rug,rum,rep,res,rhe,ria,rie,rik,rea,rat,raw,rax,ray,reb,red,ree,ref,reg,reh,rel,rab,rad,put,pus,pya,pyr,rag,raj,ram,ran,rap,ras,pua,psi,pud,pug,pry,owd,owe,owk,owl,own,oxy,pac,pad,pah,pal,pam,pan,par,ory,ose,osc,ort,ore,orf,ora,orb,orc,ope,opt,oto,ouf,our,out,ova,ona,one,ons,oka,oki,old,ole,ohm,ohs,ofo,oft,oer,oes,ode,ods,oda,odd,nub,noy,now,not,nut,nye,oak,oam,oar,oat,obi,och,noa,nob,nod,nog,nil,nim,nip,nit,nor,nib,new,nid,nig,neo,nep,net,pas,pat,pau,paw,pay,pea,pen,per,phi,pho,phu,pig,pik,pim,pin,pir,pis,pit,pob,pod,poe,poh,pol,pom,pot,pow,nea,nay,naw,neb,ned,nef,nap,nar,nat,naa,nae,nag,nab,nak,nam,nan,mya,mwa,mru,mus,moy,mud,mug,mot,mop,mob,mod,moe,mho,mew,mib,mid,mig,mil,min,mir,mis,mel,mem,meo,mes,meg,mat,mau,maw,may,mao,map,mar,mas,mab,mac,mad,mae,mag,mah,mal,man,lot,lou,low,lue,lug,luo,lwo,lye,lys,lie,lim,lin,lis,lit,loa,lob,lod,lof,log,lop,lab,kyu,kos,kra,kua,lac,koa,koi,kor,kin,kip,lad,lag,lai,lak,lam,lan,lao,lap,las,lat,law,lay,lea,led,lee,leg,lei,lek,leo,ler,les,let,leu,ley,kan,iyo,jag,jar,jat,kay,kea,kee,kha,khu,kil,ita,ist,itd,ito,its,iva,ive,ism,ira,ire,irk,ion,ind,ing,ink,ino,ins,ima,ila,ilk,ife,ids,imp,ida,ide,ich,ian,ibo,hsi,how,hud,hug,huk,hup,hwa,hip,his,hic,hie,hop,hos,hot,hed,hei,her,hes,het,haw,hay,hat,hau,has,hak,ham,hao,hap,had,gul,gum,gun,gup,gur,gut,gud,goa,gnu,gob,god,gif,gim,gin,gip,gio,git,goi,gol,gon,gor,gos,got,gra,foo,flo,for,fot,fou,fra,fro,fur,gab,gad,gaj,gal,gam,gan,gar,gas,gat,gaw,gay,gaz,gel,ged,gem,geo,ger,ges,get,gib,gid,fet,fen,fer,fie,fig,far,fat,fei,eyn,eye,ewe,eta,eva,eve,ers,era,erd,ere,erg,ens,eon,end,elk,elm,els,elt,emm,ems,emu,ego,eke,elb,eld,eli,edh,edo,eel,eer,eft,eat,ean,ear,dye,dub,dug,duh,dum,duo,dup,don,dop,dor,dos,dot,dow,dob,doc,dod,dit,doe,dog,dol,dom,dib,die,dig,dim,din,dis,dew,dey,dha,dhu,del,den,daw,das,dao,dap,dar,dab,dad,dae,dag,dah,dal,dam,dan,day,deb,deg,cro,baa,azo,awl,aye,bab,bac,bad,bae,bag,bal,bam,ban,bar,awd,awe,awn,ave,avo,auh,auk,aum,ati,ata,ate,ast,asa,aru,arx,ary,ase,ash,ask,asp,are,ark,arm,arn,aro,art,apt,arc,any,ape,ann,ant,ana,amy,and,ani,ama,aly,ame,ami,amp,amt,ala,aku,ake,ako,alb,ait,air,aht,ahu,aid,ail,aim,agy,aho,ago,aft,ale,alk,aln,alo,alp,alt,ady,adz,aer,aes,ado,ads,add,ade,yoe,yew,yeo,yer,yes,yet,yea,yaw,yed,yee,yen,yad,yah,yak,yam,yan,yap,yar,yas,yat,yoi,yom,yon,yor,yot,yow,yox,yuk,zad,zag,zoa,act,wob,wod,wit,woe,wok,won,wop,wot,woy,wro,wye,was,wat,way,wea,wed,wee,wem,wen,wes,wet,wey,wha,who,wab,wad,wac,wae,wag,wah,wan,wap,war,aba,aal,aam,abb,abe,abo,aby,ach,bas,bat,baw,bay,bea,bed,bel,ben,ber,bey,bid,big,bim,bin,bis,bit,blo,boa,bod,bog,bom,bon,bor,bop,bos,bow,bra,bud,bun,bur,bus,but,bye,cab,cal,cam,cap,car,cat,caw,cha,chi,cho,cit,cod,cor,cos'.split(','), arr=[],result=[];

for(var i=0,len=words.length;i<len;i++){
        var sort=words[i].split('').sort().join('');
        if(result.contains(sort)==false)
        {
            result.push(new Sort(sort));
            result[result.length-1].items=[words[i]];
        }
        else result[result.indexOf(sort)].add(words[i]);
    }   
    for(var i=0,l=result.length;i<l;i++)
    {
            var tmp=result[i],tmpit=result[i].items;
            document.write(tmp+':'+tmpit.join(',')+'<br/>');
    }

posted @ 2010-11-26 22:54  陈锐达  阅读(3038)  评论(0编辑  收藏  举报