Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (() => {
- const COLUMN_LENGTH = 10;
- function formatCol(q) {
- return q.length > COLUMN_LENGTH ?
- q.slice(0, COLUMN_LENGTH) :
- q + '\u2000'.repeat(COLUMN_LENGTH - q.length);
- }
- function formatRow(cols) {
- var ret = '| ';
- ret += cols.map(formatCol).join(' | ');
- ret += ' |';
- return ret;
- }
- var countries = {
- // https://en.wikipedia.org/wiki/Economy_of_Russia
- Russia: {
- gdp: 8000,
- grow: -1.2
- },
- Tajikistan: {
- gdp: 1100,
- grow: 6.6
- },
- // https://en.wikipedia.org/wiki/Economy_of_the_United_States
- USA: {
- gdp: 57293,
- grow: 1.4
- },
- };
- var countryNames = Object.keys(countries);
- var head = formatRow(['Year/Country'].concat(countryNames));
- var data = [head];
- for (let year = 2017, row; year <= 2040; ++year) {
- row = [year + ''];
- for (let index = 0, country; index < countryNames.length; ++index) {
- country = countries[countryNames[index]];
- country.gdp = Math.ceil(country.gdp * (100 + country.grow) / 100);
- row.push(country.gdp + '');
- }
- data.push(formatRow(row));
- }
- console.log(data.join('\n'));
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement