-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path03.js
More file actions
47 lines (29 loc) · 938 Bytes
/
Copy path03.js
File metadata and controls
47 lines (29 loc) · 938 Bytes
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
let csvToJson = require('convert-csv-to-json');
let a = [];
let json = csvToJson.formatValueByType().getJsonFromCsv('data.csv');
for (let i=0; i<json.length;i++){
a.push(json[i]);
}
console.log(a);
function sortByproperty(property){
return function (a,b) {
if (a[property] > b[property])
return 1;
else if(a[property] < b[property])
return -1;
return 0;
}
}
a.sort(sortByproperty('Price'));
let getAngka = a.map((el) => {
const angka = el.Price;
let rupiah = '';
let angkaModif = angka.toString().split('').reverse().join('');
for(var i = 0; i < angkaModif.length; i++)
if(i%3== 0) rupiah += angkaModif.substr(i,3) + '.';
return `Rp.${rupiah.split('',rupiah.length-1).reverse().join('')}`;
});
a.forEach((el,i) => {
el.Price = getAngka[i];
});
console.log(a);