-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathloopchallange_marketcap02.js
More file actions
201 lines (134 loc) · 10 KB
/
Copy pathloopchallange_marketcap02.js
File metadata and controls
201 lines (134 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
/*
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▄█░░░░▌
▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▄█░█▄▄▄▄▄▄▄█░█▄▐░░▌▐░░▌
▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░░░░░▌▀▀ ▐░░▌
▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▀█░█▀▀▀▀▀▀▀█░█▀ ▐░░▌
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▐░░▌
▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀█░█▀▀ ▐░▌ ▄█░█▄▄▄▄▄▄▄█░█▄ ▐░░▌
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░░░░░▌ ▐░░▌
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▀█░█▀▀▀▀▀▀▀█░█▀▄▄▄▄█░░█▄▄▄
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░▌
▀ ▀ ▀ ▀ ▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀
*/
//__|||__\\//__|||__\\//__|||__\\//__|||__\\//__|||__\\
let fileSystem = require("fs")
let rawData = fileSystem.readFileSync("./userdata001.txt", "utf-8")
// console.log(rawData.length);
let parsedData = rawData.split('\n')
let newData = []
//console.log(parsedData.length);
for (let i = 0; i < parsedData.length; i++) {
if (parsedData[i][0] == "[" && !isNaN(parseInt(parsedData[i][2]))) {
//keep and convert element
let subarray = parsedData[i]
.replace(']', '')
.replace('[', '')
.replace('$','')
.trim()
.split(',')
//console.log(subarray);
newData.push(subarray);
// } else { parsedData.splice(i,1)
// i--
//remove elemnent
}
//console.log( parsedData[i][0])
}
//console.log(newData);
//__|||__\\//__|||__\\//__|||__\\//__|||__\\//__|||__\\
/*
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░▌
▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌ ▀▀▀▀█░█▀▀▀▀ ▄█░█▄▄▄▄▄▄▄█░█▄ ▀▀▀▀▀▀▀▀▀█░▌
▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░░░░░▌ ▐░▌
▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌ ▐░▌ ▀█░█▀▀▀▀▀▀▀█░█▀ ▐░▌
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌ ▐░▌ ▄▄▄▄▄▄▄▄▄█░▌
▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀█░█▀▀ ▐░▌ ▄█░█▄▄▄▄▄▄▄█░█▄ ▐░░░░░░░░░░░▌
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░░░░░▌▐░█▀▀▀▀▀▀▀▀▀
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▀█░█▀▀▀▀▀▀▀█░█▀ ▐░█▄▄▄▄▄▄▄▄▄
▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░▌ ▐░░░░░░░░░░░▌
▀ ▀ ▀ ▀ ▀ ▀ ▀ ▀ ▀▀▀▀▀▀▀▀▀▀▀
*/
//--|||--//\\--|||--//\\--|||--//\\--|||--//\\--|||--//
/*
[0]id,
[1]first_name,
[2]last_name,
[3]email,
[4]gender,
[5]currency,
[6]Stock Market Cap
*/
//stores elements without n/a
let noNa = [];
//gets rid of an n/a elements
for (let i = 0; i < newData.length; i++) {
if (newData[i][6] != 'n/a') {
noNa.push(newData[i])
}
};
//findng the last index of the string
//console.log(noNa[0][6]);
//console.log(noNa[0][6][noNa[0][6].length - 1] === 'B');
;
let sum = 0
for (let i = 0; i < noNa.length; i++) {
let letter = noNa[i][6][noNa[i][6].length - 1]
let num1 = noNa[i][6]
if (letter === 'B' && noNa[i][5] == 'Dollar') {
let num2 = num1.slice(0,-1)
let num3 = parseFloat(num2 * (10**9))
sum += num3
//console.log(`${noNa[i][1]} ${noNa[i][2]} is ${noNa[i][4]} and has \$${num3.toLocaleString()} ${noNa[i][5]} in stocks`);
}else if (noNa[i][5] == 'Dollar') {
let num2 = num1.slice(0,-1)
let num3 = parseFloat(num2 * (10**6))
sum += num3
//console.log(`${noNa[i][1]} ${noNa[i][2]} is ${noNa[i][4]} and has \$${num3.toLocaleString()} ${noNa[i][5]} in stocks`);
}
}
//console.log(`The total market cap of the dollar is \$${sum.toLocaleString()}`);
/*
▄ ▄ ▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄▄ ▄ ▄ ▄ ▄▄▄▄▄▄▄▄▄▄▄ ▄ ▄
▐░▌ ▐░▌ ▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░░▌ ▐░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌
▄█░█▄▄▄▄▄▄▄█░█▄ ▐░█▀▀▀▀▀▀▀█░▌▐░█▀▀▀▀▀▀▀█░▌▐░▌░▌ ▐░▌▐░▌ ▐░▌▐░█▀▀▀▀▀▀▀▀▀ ▄█░█▄▄▄▄▄▄▄█░█▄
▐░░░░░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░░░░░░░░░░░░░░░▌
▀█░█▀▀▀▀▀▀▀█░█▀ ▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░█▄▄▄▄▄▄▄▄▄ ▀█░█▀▀▀▀▀▀▀█░█▀
▐░▌ ▐░▌ ▐░░░░░░░░░░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌
▄█░█▄▄▄▄▄▄▄█░█▄ ▐░█▀▀▀▀▀▀▀█░▌▐░▌ ▐░▌▐░▌ ▐░▌ ▐░▌▐░▌ ▐░▌ ▀▀▀▀▀▀▀▀▀█░▌ ▄█░█▄▄▄▄▄▄▄█░█▄
▐░░░░░░░░░░░░░░░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌ ▐░▌▐░▌▐░▌ ▐░▌ ▐░▌▐░░░░░░░░░░░░░░░▌
▀█░█▀▀▀▀▀▀▀█░█▀ ▐░█▄▄▄▄▄▄▄█░▌▐░█▄▄▄▄▄▄▄█░▌▐░▌ ▐░▐░▌▐░█▄▄▄▄▄▄▄█░▌ ▄▄▄▄▄▄▄▄▄█░▌ ▀█░█▀▀▀▀▀▀▀█░█▀
▐░▌ ▐░▌ ▐░░░░░░░░░░▌ ▐░░░░░░░░░░░▌▐░▌ ▐░░▌▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌ ▐░▌ ▐░▌
▀ ▀ ▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ ▀ ▀
*/
function millOrBill(array) {
let letter = array[array.length - 1]
if (array != 'n/a') {
if (letter == 'B') {
let num = parseFloat(array.slice(0,-1) * (10**9))
return num
} else {
let num = parseFloat(array.slice(0,-1) * (10**6))
return num
}
}
}
// console.log(millOrBill(noNa[0][6]) );
let currency = []
for (let i = 0; i < noNa.length; i++) {
if (currency.indexOf(noNa[i][5]) == -1) {
currency.push(noNa[i][5])
currency.sort()
}
}
// console.log(currency);
for (let i = 0; i < currency.length; i++) {
let num = 0
for (let j = 0; j < noNa.length; j++) {
if (noNa[j][5] == currency[i]) {
num += millOrBill(noNa[j][6])
}
}
console.log(`-----------------------------\nThe total marketcap for the ${currency[i]} is ${num}\n----------------------------- `);
}