Advertisement
xapu

Untitled

Jun 7th, 2017
340
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. function Eight(first,second){
  3. let params = arguments[0]
  4. let length = Number(first)
  5. let height = Number(second)
  6. let endNum = length*height
  7. let myArr =[]
  8. let cur=1
  9.  
  10.  
  11. for(let i=0; i<length;i++){
  12. if(i==length-1-i){
  13. myArr[i][i]=cur
  14. }
  15.  
  16. for(let j=i; j<length-1-i;j++){
  17. if(!Array.isArray(myArr[i])){
  18. myArr[i]=new Array()
  19. }
  20. myArr[i][j]=cur
  21. endNum==cur?cur+=0:cur++
  22.  
  23. }
  24. for(let goDown=i; goDown<length-i-1;goDown++){
  25.  
  26. if(!Array.isArray(myArr[goDown])){
  27. myArr[goDown]=new Array()
  28. }
  29. myArr[goDown][length-1-i]=cur
  30. endNum==cur?cur+=0:cur++
  31. }
  32. for( let goLeft=i; goLeft<length-i-1;goLeft++){
  33. if(!Array.isArray(myArr[length-1])){
  34. myArr[length-1]=new Array()
  35. }
  36. myArr[length-1-i][length-1-goLeft]=cur
  37. endNum==cur?cur+=0:cur++
  38. }
  39. for(let goUp = i; goUp<length-1-i;goUp++){
  40. myArr[length-1-goUp][i]=cur
  41. endNum==cur?cur+=0:cur++
  42. }
  43. }
  44. myArr.map(x=>{
  45. console.log(x.join(' '))
  46. })
  47. }
  48.  
  49. Eight(10,5)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement