Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. var _ = require('underscore');
  2.  
  3. function sayHello() {
  4. console.log('Hello, World');
  5. }
  6.  
  7. _.times(5, sayHello);
  8.  
  9.  
  10. /*
  11. Your previous Plain Text content is preserved below:
  12.  
  13. This is just a simple shared plaintext pad, with no execution capabilities.
  14.  
  15. When you know what language you'd like to use for your interview,
  16. simply choose it from the dropdown in the top bar.
  17.  
  18. You can also change the default language your pads are created with
  19. in your account settings: https://coderpad.io/settings
  20.  
  21. Enjoy your interview!
  22.  
  23. 1 2 3
  24. 8 9 4
  25. 7 6 5
  26.  
  27. [[1 2 3] [8 9 4] [7 6 5]]
  28. => [1 2 3 4 15 6 7 8 9]
  29.  
  30. 1 2 3 4
  31. 8 7 6 5
  32.  
  33. [[1 2 3 4] [8 7 6 5]]
  34. => [1 2 3 4 5 6 7 8]
  35.  
  36. [] spiralIn([][])
  37. */
  38. // x*y, x, xth second row,
  39. // 1 2 3 4
  40. // 5 6 7 8
  41. // 9 1 2 3
  42. // 1 2 3 4
  43.  
  44. // var myArr = [[1, 2, 3], [8, 9, 4], [7, 6, 5]];
  45.  
  46. var myArr = [[1, 2, 3, 4], [5, 6, 7, 8], [9, 1, 2, 3,], [1,2,3,4] ];
  47. console.log("Starting Array:");
  48. console.log(myArr);
  49.  
  50. function spiralIn(arr, lastOutput){
  51.  
  52. var output = lastOutput || [];
  53. output.push.apply(output, arr.shift());
  54.  
  55. if(!arr.length) return output;
  56.  
  57. arr.forEach( (item) => {
  58. output.push(item.pop());
  59. });
  60.  
  61. output.push.apply(output, arr.pop().reverse());
  62.  
  63. if(!arr.length) return output;
  64.  
  65. for (var x = arr.length-1; x>=0; x--){
  66. output.push(arr[x].shift());
  67. }
  68.  
  69. if(!arr.length) return output;
  70.  
  71. return spiralIn(arr, output);
  72.  
  73. }
  74.  
  75. console.log("Output array:");
  76. console.log(spiralIn(myArr));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement