Advertisement
stuppid_bot

Untitled

Oct 23rd, 2016
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. (() => {
  2.   const COLUMN_LENGTH = 10;
  3.  
  4.   function formatCol(q) {
  5.     return q.length > COLUMN_LENGTH ?
  6.       q.slice(0, COLUMN_LENGTH) :
  7.       q + '\u2000'.repeat(COLUMN_LENGTH - q.length);
  8.   }
  9.  
  10.   function formatRow(cols) {
  11.     var ret = '| ';
  12.     ret += cols.map(formatCol).join(' | ');
  13.     ret += ' |';
  14.     return ret;
  15.   }
  16.  
  17.   var countries = {
  18.     // https://en.wikipedia.org/wiki/Economy_of_Russia
  19.     Russia: {
  20.       gdp: 8000,
  21.       grow: -1.2
  22.     },
  23.     Tajikistan: {
  24.       gdp: 1100,
  25.       grow: 6.6
  26.     },
  27.     // https://en.wikipedia.org/wiki/Economy_of_the_United_States
  28.     USA: {
  29.       gdp: 57293,
  30.       grow: 1.4
  31.     },
  32.   };
  33.  
  34.   var countryNames = Object.keys(countries);
  35.   var head = formatRow(['Year/Country'].concat(countryNames));
  36.   var data = [head];
  37.   for (let year = 2017, row; year <= 2040; ++year) {
  38.     row = [year + ''];
  39.     for (let index = 0, country; index < countryNames.length; ++index) {
  40.       country = countries[countryNames[index]];
  41.       country.gdp = Math.ceil(country.gdp * (100 + country.grow) / 100);
  42.       row.push(country.gdp + '');
  43.     }
  44.     data.push(formatRow(row));
  45.   }
  46.   console.log(data.join('\n'));
  47. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement