Guest User

Tables

a guest
Nov 12th, 2014
159
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function printPricesTrendsTable(input) {
  2.     var prices = input.map(Number);
  3.     console.log("<table>");
  4.     console.log("<tr><th>Price</th><th>Trend</th></tr>");
  5.     var prevPrice = undefined;
  6.     for (var i = 0; i < prices.length; i++) {
  7.         var price = prices[i];
  8.         var priceStr = price.toFixed(2);
  9.         if (prevPrice == undefined || priceStr == prevPrice) {
  10.             var trend = "fixed.png";
  11.         } else if (price < prevPrice) {
  12.             var trend = "down.png";
  13.         } else {
  14.             var trend = "up.png";
  15.         }
  16.         console.log("<tr><td>" + priceStr + "</td><td><img src=\"" + trend + "\"/></td></tr>");
  17.         prevPrice = priceStr;
  18.     }
  19.     console.log("</table>");
  20. }
RAW Paste Data