Advertisement
Guest User

Untitled

a guest
Jun 28th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.06 KB | None | 0 0
  1. <html>
  2.  
  3.  
  4. <body>
  5.  
  6. <script>
  7.  
  8. var listOfPlanes = [];
  9.  
  10.  
  11. var plane0 = {
  12. name : "Angelina",
  13. id : Math.floor( Math.random() * 1000),
  14. color : "Blue" ,
  15. passengers : 16
  16. };
  17.  
  18. var plane1 = {
  19. name : "Angela",
  20. id : Math.floor( Math.random() * 1000),
  21. color : "Red" ,
  22. passengers : 44
  23. };
  24.  
  25. var plane2 = {
  26. name: "Casandra",
  27. id : Math.floor( Math.random() * 1000),
  28. color : "Red" ,
  29. passengers : 44
  30. };
  31.  
  32. var plane3 = {
  33. name : "Tiffany",
  34. id : Math.floor( Math.random() * 1000),
  35. color : "Blue" ,
  36. passengers : 33
  37. };
  38.  
  39. var plane4 = {
  40. name : "Ivrian",
  41. id : Math.floor( Math.random() * 1000),
  42. color : "Grey" ,
  43. passengers : 55
  44. }
  45.  
  46. var plane5 = {
  47. name : "Ajino",
  48. id : Math.floor( Math.random() * 1000),
  49. color : "Black" ,
  50. passengers : 66
  51. };
  52.  
  53. var plane6 = {
  54. name : "Emelita",
  55. id : Math.floor( Math.random() * 1000),
  56. color : "Grey" ,
  57. passengers : 33
  58. };
  59.  
  60. var plane7 = {
  61. name : "Maria",
  62. id : Math.floor( Math.random() * 1000),
  63. color : "Red" ,
  64. passengers : 11
  65. };
  66.  
  67. var plane8 = {
  68. name : "Celerina",
  69. id : Math.floor( Math.random() * 1000),
  70. color : "Red" ,
  71. passengers : 22
  72. };
  73.  
  74. var plane9 = {
  75. name : "Keanu",
  76. id : Math.floor( Math.random() * 1000),
  77. color : "NA" ,
  78. passengers : 22
  79. };
  80.  
  81. var plane10 = {
  82. name : "Yuliana",
  83. id : Math.floor( Math.random() * 1000),
  84. color : "Red" ,
  85. passengers : 55
  86. };
  87.  
  88. var plane11 = {
  89. name : "Francisco",
  90. id : Math.floor( Math.random() * 1000),
  91. color : "Black" ,
  92. passengers : 11
  93. };
  94.  
  95. var plane12 = {
  96. name : "Carlos",
  97. id : Math.floor( Math.random() * 1000),
  98. color : "Black" ,
  99. passengers : 73
  100. };
  101.  
  102. var listOfBlackPlanes
  103. var listOfRedPlanes
  104.  
  105.  
  106. listOfPlanes.push(plane0);
  107. listOfPlanes.push(plane1);
  108. listOfPlanes.push(plane2);
  109. listOfPlanes.push(plane3);
  110. listOfPlanes.push(plane4);
  111. listOfPlanes.push(plane5);
  112. listOfPlanes.push(plane6);
  113. listOfPlanes.push(plane7);
  114. listOfPlanes.push(plane8);
  115. listOfPlanes.push(plane9);
  116. listOfPlanes.push(plane10);
  117. listOfPlanes.push(plane11);
  118. listOfPlanes.push(plane12);
  119.  
  120.  
  121. function moreThanThirty(arrayOfPlanes)
  122. {
  123. var planesOfThirty = [];
  124.  
  125. for (var i = 0; i < arrayOfPlanes.length; i++)
  126. {
  127. var currentPlane = arrayOfPlanes[i];
  128.  
  129. if(currentPlane.passengers > 30)
  130. {
  131. planesOfThirty.push(currentPlane);
  132.  
  133. }
  134.  
  135. }
  136.  
  137. return planesOfThirty;
  138. }
  139.  
  140.  
  141.  
  142. function sortByColor(unsortedStack)
  143. {
  144. var sortedStack = [];
  145. var elementsInSortedStack = 0;
  146.  
  147. sortedStack.push( unsortedStack.shift() );
  148. elementsInSortedStack = 1;
  149.  
  150.  
  151. while (unsortedStack.length != 0 )
  152. {
  153.  
  154. for (var i = 0; i < unsortedStack.length; i++)
  155. {
  156. if (unsortedStack[i] == sortedStack[elementsInSortedStack - 1] )
  157. {
  158. sortedStack.push( unsortedStack.splice(i, 1) );
  159. elementsInSortedStack ++;
  160. }
  161.  
  162.  
  163.  
  164. }
  165.  
  166.  
  167.  
  168. i = 0;
  169. }
  170.  
  171.  
  172. return sortedStack;
  173.  
  174. } //closing brace of function sortByColor
  175.  
  176.  
  177.  
  178. //console.log( moreThanThirty(listOfPlanes) );
  179. console.log(sortByColor(listOfPlanes) );
  180.  
  181.  
  182.  
  183.  
  184.  
  185. </script>
  186.  
  187. </body>
  188.  
  189.  
  190. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement