Advertisement
aluin

Exam-2907-task01-pricesTrends

Jul 30th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. function solve(input) {
  2. var output = '<table>\n<tr><th>Price</th><th>Trend</th></tr>\n';
  3. var first = 0;
  4. for (var i = 0; i < input.length; i++) {
  5. var num = parseFloat(input[i]);
  6. num = num.toFixed(2);
  7.  
  8. if (isNaN(num)){
  9. output += '<tr><td>-</td><td><img src="fixed.png"/></td></td>\n';
  10. } else {
  11. if (parseFloat(num) === parseFloat(first) || i === 0) {
  12. output += '<tr><td>' + num + '</td><td><img src="fixed.png"/></td></td>\n';
  13. } else if (parseFloat(num) > parseFloat(first)) {
  14. output += '<tr><td>' + num + '</td><td><img src="up.png"/></td></td>\n';
  15. } else if (parseFloat(num) < parseFloat(first)) {
  16. output += '<tr><td>' + num + '</td><td><img src="down.png"/></td></td>\n';
  17. }
  18. }
  19. first = num;
  20. }
  21.  
  22. return output + '</table>';
  23. }
  24.  
  25. console.log(solve(['1000000', '99000']));
  26. console.log(solve(['36.333', '36.5', '37.019', '35.4', '35', '35.001', '36.255']));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement