第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

關(guān)于前端面試題

關(guān)于前端面試題

叢從綠草 2019-01-22 14:27:13
給定行數(shù)和列數(shù),寫3個函數(shù)分別輸出如下的二維數(shù)組(假設(shè)給的行數(shù)是5,列數(shù)是4):1 2 3 45 6 7 8?9 10 11 1213 14 15 1617 18 19 20?1 6 11 16?2 7 12 173 8 13 184 9 14 195 10 15 201 10 11 20?2 9 12 193 8 13 184 7 14 175 6 15 16這個怎么做啊??(function(window,?document)?{ let?sorts?=?function(option)?{ ????this._init(option); }; sorts.prototype._init?=?function(option)?{ this.arrs?=?option.arr; this.rows?=?option.rows; this.cols?=?option.cols; this._create(); }; sorts.prototype._create?=?function(option)?{ let?nums?=?0; for?(let?i?=?0;?i?<?this.rows;?i++)?{ document.write('<br>'); for?(let?j?=?0;?j?<?this.cols;?j++)?{ if?(this.arrs[nums])?{ document.writeln(this.arrs[nums]); nums++; } } } }; window.sorts?=?sorts })(window,?document); new?sorts({ ????rows:?5, ????cols:?4, ????arr:?['1',?'2',?'3',?'4',?'5',?'6',?'7',?'8',?'9',?'10',?'11',?'12',?'13',?'14',?'15',?'16',?'17',?'18',?'19',?'20'] });?這個類型不能算。
查看完整描述

1 回答

已采納
?
pardon110

TA貢獻(xiàn)1038條經(jīng)驗(yàn) 獲得超227個贊

關(guān)鍵是寫出行列之間的關(guān)系 如下所示

//?橫書
function?rowFirst(rows,cols){
??n?=?1
??arr?=?[]
???for?(i=0;?i?<?rows;?i++){
????s?=?''
????arr[i]?=?[]
????????for(j=0;j<cols;j++,n++){
????????arr[i].push(n)
????????s?+=?n?+?'?'
????????}
????console.log(s+"\n")
????}
??return?arr;
}
//?lineFirst(5,4)

//?豎版
function?colsFirst(rows,cols){
???arr?=?[]
????for?(i=0;?i?<?rows;?i++){
?????s?=?''
?????arr[i]?=?[]
?????for(j=0;j<cols;j++){
???????arr[i].push(i+1+rows*j)
???????s?+=?arr[i][j]?+?'?'
?????}
?????console.log(s+"\n")
????}
??return?arr;
}
//?colsFirst(5,4)

//?之走
function?reverseFisrt(rows,cols){
???arr?=?[]
????for?(i=0;?i?<?rows;?i++){
???????s?=?''
???????arr[i]?=?[]
????????for(j=0;j<cols;j++){
????????if(j%2==1){
??????????arr[i].push(rows*(j+1)-i)
????????}else{
?????????arr[i].push(i+1+rows*j)
????????}
???????s?+=?arr[i][j]?+?'?'
?????}
?????console.log(s+"\n")
????}
??return?arr;
}
console.log(reverseFisrt(5,4))

最后一個函數(shù)調(diào)用效果圖如下

2?9?12?19
3?8?13?18
4?7?14?17
5?6?15?16
[?[?1,?10,?11,?20?],
??[?2,?9,?12,?19?],
??[?3,?8,?13,?18?],
??[?4,?7,?14,?17?],
??[?5,?6,?15,?16?]?]


查看完整回答
反對 回復(fù) 2019-01-22
  • 1 回答
  • 0 關(guān)注
  • 940 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號