最近我開始學習重構代碼。我如何重構這段代碼。我可以從哪裏開始?如何重構這段代碼?
var activeNumber = [
{ name: 'no 1' },
{ name: 'no 2' },
{ name: 'no 11' },
{ name: 'no 3' },
{ name: 'no 10' }
];
var numberRe = new RegExp('\\d+');
var getCustomNumber = function() {
var top = 0;
for (var i = 0; i < activeNumber.length; i++) {
var present = numberRe.exec(activeNumber[i].name);
if (present) {
var neno = parseInt(present[0]);
if (!isNaN(neno) && neno > top) {
top = neno;
}
}
}
return top;
};