Guest User

Untitled

a guest
Mar 6th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function clockwise(input, width, height) {
  12. const nav = [1, width, -1, -width]
  13. const count = [width, height]
  14. const output = []
  15. for (let i = 0, p = 0; output.length < input.length; p += 1, count[p % 2] -= 1, i += nav[p % 4] - nav[(p - 1) % 4]) {
  16. for (let j = 0; j < count[p % 2]; j += 1, i += nav[p % 4]) {
  17. output.push(input[i])
  18. }
  19. }
  20. return output
  21. }
  22.  
  23. const input = [
  24. 0, 1, 2, 3, 4,
  25. 5, 6, 7, 8, 9,
  26. 10, 11, 12, 13, 14,
  27. 15, 16, 17, 18, 19,
  28. 20, 21, 22, 23, 24,
  29. ]
  30. const output = clockwise(input, 5, 5)
  31. console.log(output)
  32. </script>
  33.  
  34.  
  35.  
  36. <script id="jsbin-source-javascript" type="text/javascript">function clockwise(input, width, height) {
  37. const nav = [1, width, -1, -width]
  38. const count = [width, height]
  39. const output = []
  40. for (let i = 0, p = 0; output.length < input.length; p += 1, count[p % 2] -= 1, i += nav[p % 4] - nav[(p - 1) % 4]) {
  41. for (let j = 0; j < count[p % 2]; j += 1, i += nav[p % 4]) {
  42. output.push(input[i])
  43. }
  44. }
  45. return output
  46. }
  47.  
  48. const input = [
  49. 0, 1, 2, 3, 4,
  50. 5, 6, 7, 8, 9,
  51. 10, 11, 12, 13, 14,
  52. 15, 16, 17, 18, 19,
  53. 20, 21, 22, 23, 24,
  54. ]
  55. const output = clockwise(input, 5, 5)
  56. console.log(output)
  57. </script></body>
  58. </html>
Add Comment
Please, Sign In to add comment