Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Eight(first,second){
- let params = arguments[0]
- let length = Number(first)
- let height = Number(second)
- let endNum = length*height
- let myArr =[]
- let cur=1
- for(let i=0; i<length;i++){
- if(i==length-1-i){
- myArr[i][i]=cur
- }
- for(let j=i; j<length-1-i;j++){
- if(!Array.isArray(myArr[i])){
- myArr[i]=new Array()
- }
- myArr[i][j]=cur
- endNum==cur?cur+=0:cur++
- }
- for(let goDown=i; goDown<length-i-1;goDown++){
- if(!Array.isArray(myArr[goDown])){
- myArr[goDown]=new Array()
- }
- myArr[goDown][length-1-i]=cur
- endNum==cur?cur+=0:cur++
- }
- for( let goLeft=i; goLeft<length-i-1;goLeft++){
- if(!Array.isArray(myArr[length-1])){
- myArr[length-1]=new Array()
- }
- myArr[length-1-i][length-1-goLeft]=cur
- endNum==cur?cur+=0:cur++
- }
- for(let goUp = i; goUp<length-1-i;goUp++){
- myArr[length-1-goUp][i]=cur
- endNum==cur?cur+=0:cur++
- }
- }
- myArr.map(x=>{
- console.log(x.join(' '))
- })
- }
- Eight(10,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement