This article illustrates the method of jquery to realize the number selection of mobile phone numbers. Share to everyone for your reference. Specifically as follows:
Some time ago to see the free combination of Unicom package is very tempting and decided to change the number, but the number was a very tiring job. In the free number list for a long time did not choose the right number, so wrote a script to analyze these mobile phone numbers, although not very accurate, but at least the pile of garbage number filtered out. Welcome to Pat Bricks.
Code relies on jquery and is interested in refactoring to remove dependencies.
It is recommended that you use the Chrome browser's debugging tools to execute.
jquery cell phone number analysis score:
/*class*/regexpmatchscorer = function (/*required regexp*/reg,/*required number*/threshold) {return function (/*required char[]*/numberarray) {if (!!) Numberarray &&!! Reg &&!!
Threshold) {var matchelist = Numberarray.join (). Match (REG);
if (matchelist!= null) {return matchelist.length * threshold;
} return 0;
}; //Analysis of the 8-digit number count number fraction function analysenumbers (/*required string[]*/numberlist,/*optional Object{begin,size}*/rang
E,/*optional function (char[]) []*/addtionrules) {//No 4th code scoring function Non4 (Numberarray) {var threshold = 4;
if (!numberarray.inarray ("4")) {return threshold;
return 0;
///Total number added to the highest 10-minute function Numbercount (numberarray) {var threshold = 10;
var charcount = Uniquearray (numberarray). length;
Return Threshold-((charCount-1) * (Threshold/(numberarray.length-1));
}///repeat times Add function adjoinrepeat (numberarray) {var threshold = 2;
var score = 0; for (Var i=1;i<numberarray.length;i++) {var times = 0;
if (numberarray[i-1] = = Numberarray[i]) {times++;
Score+=threshold*times;
}else{times=0;
} return score;
}//cis-plus (3-bit) function straight (Numberarray) {var threshold = 2.5;
var sidetimes = 2.5//cis number at both ends 2.5 times times the score var inversetimes = 0.6 var score = 0;
for (Var i=2;i<numberarray.length;i++) {var stimes = 0;
var itimes = 0; if ((number (numberarray[i)) -1==number (numberarray[i-1]) && number (numberarray[i)) -2==number (numberarray[ I-2]) && ++stimes) | | (Number (Numberarray[i]) +1==number (numberarray[i-1]) && number (numberarray[i)) +2==number (numberarray[i-2)
) (&& ++itimes)) {var sc = 0;
if (i = = 2 | | | i = = numberarray.length-1) {sc = threshold*sidetimes;//number at both ends 2.5 times times the score}else{sc = threshold;
} score + = SC * (stimes + itimes*inversetimes);
}else{stimes=0;
itimes=0;
} return score;
}//array to complex function Uniquearray (Parr) { function _unique (_arr, i) {if (i>=_arr.length) {return;
} if (_arr[i] = = _arr[i+1]) {_arr.splice (i+1,1);
_unique (_arr,i);
}else{_unique (_arr,i+1);
} var Arr=parr.slice (). sort ();
_unique (arr,0);
return arr;
/************* * Scoring logic **************/var nonrepeatlist = Uniquearray (numberlist); var scorerlist = [Non4, Numbercount, Adjoinrepeat, Straight, new Regexpmatchscorer (New RegExp ("6|8|
9) "," G "), 0.7)]; if (!!
Addtionrules) {scorerlist.concat (addtionrules);
} var scoretable = [];
Analysis number Nonrepeatlist.foreach (function (data) {var score = 0;
var pn = data.tostring (); if (!!
Range) {pn = Pn.substr (Range.begin, range.size);
var Numberarray = Pn.split ("");
Scorerlist.foreach (function (scorer) {score + = scorer (Numberarray.slice ());
});
Publish score Scoretable.push ({"Number":d ata, "score": Score});
});
return scoretable;
}
Crawl number list, analysis:
The var URL must be executed under num.10010.com
= "http://num.10010.com/numapp/goodsdetail/querymorenums?callback=& Province=51&citycode=540&rankmoney=&groupkey=65070778&mid=&q_p=51&net=01&rolevalue =&prefeesel=0&keyvalue=&show4gnum=true&q_p= ";
var nl = [];
for (Var i=1;i<=50;i++) {
var Urli = url+i;
$.get (Urli,function (data,status) {
var _json = eval (data);
For (Var j=0;j< (_JSON.MORENUMARRAY.LENGTH/7); j + +) {
var idx = j*7;
var num = _json.morenumarray[idx];
Nl.push (num);}}
);
Wait for the above code crawl number after the analysis number
/check xx more than the number
(function (SC) {var x=[];analysenumbers (Nl,{begin:-8,size:8}). ForEach ( function (d,i) {if (D.SCORE>=SC) X.push (d.number+ ":" +d.score);}); Return X.sort (). Join ("\ n");})
(/*SCORE*/10);
I hope this article will help you with your jquery programming.