Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. "use strict";
  2.  
  3. function getDateTime()
  4. {
  5. var date = new Date();
  6. var space = " "
  7. var colon = ":"
  8. var dot = "."
  9. var year = date.getFullYear();
  10. var month = ('0'+date.getMonth()+1).slice(-2);
  11. var day = ('0'+date.getDate()).slice(-2);
  12. var hours = ('0'+date.getHours()).slice(-2);
  13. var minutes = ('0'+date.getMinutes()).slice(-2);
  14. var seconds = ('0'+date.getSeconds()).slice(-2);;
  15. console.log(day + dot + month + dot + year + space + hours + colon + minutes + colon + seconds);
  16. }
  17.  
  18. function Sort1(arr)
  19. {
  20. for(var i = 0; i < arr.length; i++)
  21. {
  22. for(var j = i + 1; j < arr.length; j++)
  23. {
  24. if(arr[j] < arr[i])
  25. {
  26. var temp = arr[i];
  27. arr[i] = arr[j];
  28. arr[j] = temp;
  29. }
  30. }
  31. }
  32. }
  33.  
  34. function Sort2(arr)
  35. {
  36. var arrLength = arr.length;
  37. var swapped;
  38. do
  39. {
  40. swapped = false;
  41. for(var i = 0; i < arrLength-1; i++)
  42. {
  43. if(arr[i] > arr[i+1])
  44. {
  45. var temp = arr[i];
  46. arr[i] = arr[i+1];
  47. arr[i+1] = temp;
  48. }
  49. }
  50. }
  51. while(swapped);
  52. }
  53.  
  54. function generateRandomArr(min, max, len)
  55. {
  56. var arr = [];
  57. min = Math.ceil(min);
  58. max = Math.floor(max);
  59. for(var i = 0; i < len; i++)
  60. {
  61. arr.push(Math.floor(Math.random() * (max - min + 1)) + min);
  62. }
  63. return arr;
  64. }
  65.  
  66. function splitArrayToArrays(array, sizeOfSplit)
  67. {
  68. var tempArray = new Array();
  69. var returnArray = new Array(new Array());
  70. for (var x = 0; x < array.length; x += sizeOfSplit)
  71. {
  72. //console.log(x);
  73. tempArray = array.slice(x, x + sizeOfSplit);
  74. returnArray[x] = tempArray;
  75. }
  76. return returnArray;
  77. }
  78.  
  79. function createAndPrintDiscountedPricesTable(minPrice, maxPrice, priceIncrement, discount)
  80. {
  81. var startingPrices = [];
  82. for(var price = minPrice; price <= maxPrice; price += priceIncrement)
  83. {
  84. startingPrices.push(price);
  85. }
  86.  
  87. var discountedPrices = [];
  88. for(var i = 0; i < startingPrices.length; i++)
  89. {
  90. discountedPrices.push(startingPrices[i] * discount);
  91. }
  92.  
  93. var splitSize = Math.ceil(startingPrices.length/4);
  94.  
  95. var fourColumnStartingPrices = splitArrayToArrays(startingPrices, splitSize);
  96. var fourColumnDiscountedPrices = splitArrayToArrays(discountedPrices, splitSize);
  97.  
  98. console.debug(fourColumnStartingPrices);
  99.  
  100. //val1.toFixed(trailingSize).toString().padStart(padding).padEnd(padding);
  101. // console.log("-------------------------");
  102. // console.log(fourColumnStartingPrices[0].toString());
  103. // console.log("-------------------------");
  104. // console.log("-------------------------");
  105. // console.log(fourColumnStartingPrices[1][0]);
  106. // console.log("-------------------------");
  107.  
  108. var padding = 10;
  109. var trailingSize = 2;
  110.  
  111. }
  112.  
  113. // var values1 = generateRandomArr(1, 250, 500);
  114. // var values2 = values1;
  115. // console.log("Original Values:\n" + values1);
  116. // Sort1(values1);
  117. // console.log("Values sorted with Sort1():\n" + values1);
  118. // Sort2(values2);
  119. // console.log("Values sorted with Sort2():\n" + values2);
  120.  
  121. createAndPrintDiscountedPricesTable(1, 100, 0.25, 0.85);
  122.  
  123. //getDateTime();
  124. //var timer = setInterval(getDateTime, 2000);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement