- function range (low, high) {
- // <a href="http://phpjs.org/functions/range:499">http://phpjs.org/functions/range:499
- var matrix = [];
- var inival, endval, plus;
- var chars = false;
- if ( /^\\d+$/.test(low) && /^\\d+$/.test(high) ) {
- inival = parseInt(low);
- endval = parseInt(high);
- } else {
- chars = true;
- inival = low.charCodeAt(0);
- endval = high.charCodeAt(0);
- }
- plus = (inival > endval) ? false : true;
- if (plus) {
- while (inival <= endval) {
- matrix.push( chars ? String.fromCharCode(inival) : inival );
- inival += 1;
- }
- } else {
- while (inival >= endval) {
- matrix.push( chars ? String.fromCharCode(inival) : inival );
- inival -= 1;
- }
- }
- return matrix;
- }
- //该片段来自于http://www.codesnippet.cn/detail/160520133398.html
来源: http://www.codesnippet.cn/detail/160520133398.html