Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var _ = require('underscore');
- function sayHello() {
- console.log('Hello, World');
- }
- _.times(5, sayHello);
- /*
- Your previous Plain Text content is preserved below:
- This is just a simple shared plaintext pad, with no execution capabilities.
- When you know what language you'd like to use for your interview,
- simply choose it from the dropdown in the top bar.
- You can also change the default language your pads are created with
- in your account settings: https://coderpad.io/settings
- Enjoy your interview!
- 1 2 3
- 8 9 4
- 7 6 5
- [[1 2 3] [8 9 4] [7 6 5]]
- => [1 2 3 4 15 6 7 8 9]
- 1 2 3 4
- 8 7 6 5
- [[1 2 3 4] [8 7 6 5]]
- => [1 2 3 4 5 6 7 8]
- [] spiralIn([][])
- */
- // x*y, x, xth second row,
- // 1 2 3 4
- // 5 6 7 8
- // 9 1 2 3
- // 1 2 3 4
- // var myArr = [[1, 2, 3], [8, 9, 4], [7, 6, 5]];
- var myArr = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1, 2, 3,], [1,2,3,4] ];
- console.log("Starting Array:");
- console.log(myArr);
- function spiralIn(arr, lastOutput){
- var output = lastOutput || [];
- output.push.apply(output, arr.shift());
- if(!arr.length) return output;
- arr.forEach( (item) => {
- output.push(item.pop());
- });
- output.push.apply(output, arr.pop().reverse());
- if(!arr.length) return output;
- for (var x = arr.length-1; x>=0; x--){
- output.push(arr[x].shift());
- }
- if(!arr.length) return output;
- return spiralIn(arr, output);
- }
- console.log("Output array:");
- console.log(spiralIn(myArr));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement