Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function json(input) {
- let [columns, ...table] = input.map(splitLine);
- return JSON.stringify(table.map(entry => {
- return columns.reduce((acc, curr, index) => {
- acc[curr] = entry[index];
- return acc;
- }, {})
- }));
- function splitLine(input) {
- return input.split('|')
- .filter(emptyString)
- .map(x => x.trim())
- .map(convertIfNum)
- }
- function emptyString(str) {
- return str !== '';
- };
- function convertIfNum(num) {
- return isNaN(num) ? num : Number(Number(num).toFixed(2));
- };
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement