Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2016
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. function solve(arr) {
  2. var newArr = [];
  3. for (var index in arr) {
  4. newArr.push(Number(arr[index]));
  5. }
  6.  
  7. for (var index in newArr) {
  8. newArr[index] = (Math.round(newArr[index] * 100) / 100).toFixed(2);
  9. }
  10.  
  11. var table = '<table>\n';
  12. var tableClose = '</table>\n';
  13. var tr = '<tr>';
  14. var trClose = '</tr>';
  15. var th = '<th>';
  16. var thClose = '</th>';
  17. var td = '<td>';
  18. var tdClose = '</td>';
  19.  
  20. var firstRoll = tr + th + 'Price' + thClose + th + 'Trend' + thClose + trClose + '\n';
  21. //var secondRoll = tr + td + newArr[0].toString() + tdClose + td + '<img src="down.png"/>' + tdClose + tdClose + '\n';
  22.  
  23. var output = table + firstRoll;
  24.  
  25. for (var i = 0; i < newArr.length; i++) {
  26. var str1 = '';
  27. if (i == 0) {
  28. str1 = 'fixed';
  29. }
  30. else {
  31. if (newArr[i] < newArr[i - 1]) {
  32. str1 = 'down';
  33. }
  34. if (newArr[i] > newArr[i - 1]) {
  35. str1 = 'up';
  36. }
  37. if (newArr[i] === newArr[i - 1]) {
  38. str1 = 'fixed';
  39. }
  40. }
  41.  
  42. var roll = tr + td + newArr[i].toString() + tdClose + td + '<img src="' + str1 + '.png"/>' + tdClose + tdClose + '\n';
  43. output += roll;
  44. }
  45.  
  46. output = output + tableClose;
  47.  
  48. console.log(output);
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement