Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <meta name="viewport" content="width=device-width">
- <title>JS Bin</title>
- </head>
- <body>
- <script id="jsbin-javascript">
- function clockwise(input, width, height) {
- const nav = [1, width, -1, -width]
- const count = [width, height]
- const output = []
- for (let i = 0, p = 0; output.length < input.length; p += 1, count[p % 2] -= 1, i += nav[p % 4] - nav[(p - 1) % 4]) {
- for (let j = 0; j < count[p % 2]; j += 1, i += nav[p % 4]) {
- output.push(input[i])
- }
- }
- return output
- }
- const input = [
- 0, 1, 2, 3, 4,
- 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24,
- ]
- const output = clockwise(input, 5, 5)
- console.log(output)
- </script>
- <script id="jsbin-source-javascript" type="text/javascript">function clockwise(input, width, height) {
- const nav = [1, width, -1, -width]
- const count = [width, height]
- const output = []
- for (let i = 0, p = 0; output.length < input.length; p += 1, count[p % 2] -= 1, i += nav[p % 4] - nav[(p - 1) % 4]) {
- for (let j = 0; j < count[p % 2]; j += 1, i += nav[p % 4]) {
- output.push(input[i])
- }
- }
- return output
- }
- const input = [
- 0, 1, 2, 3, 4,
- 5, 6, 7, 8, 9,
- 10, 11, 12, 13, 14,
- 15, 16, 17, 18, 19,
- 20, 21, 22, 23, 24,
- ]
- const output = clockwise(input, 5, 5)
- console.log(output)
- </script></body>
- </html>
Add Comment
Please, Sign In to add comment