請(qǐng)問(wèn)為什么console.log(listToArray(arrayToList([1,2,3])));運(yùn)行結(jié)果是[1]而不是[1,2,3]呢,第二個(gè)函數(shù)問(wèn)題出在哪里function arrayToList(arr){ var list = {}; list['value'] = arr[0]; if (arr.length > 1) { list['rest'] = arrayToList(arr.slice(1)) }else{ list['rest'] = null; } return list;}function listToArray(list){ var arr = []; for(var key in list){ if (key =='value') { console.log(1) arr.push(list[key]); }else if (key == 'rest' && list.rest != null) { console.log(2); arr.concat(listToArray(list.rest)); } } console.log(arr); return arr;}
請(qǐng)問(wèn)下面這個(gè)列表轉(zhuǎn)數(shù)組的函數(shù)錯(cuò)在哪里 ?
慕娘9325324
2018-09-11 14:15:38