I'm currently learning Node.js, javascript and so on. I come from C++.
I need to parse an array such as:
======================================================================================================
No. Name Cask Current Latest Auto-Update State
======================================================================================================
1/38 5KPlayer 5kplayer latest latest
2/38 Adobe Photoshop CC adobe-photoshop-cc 16 16
3/38 Alfred alfred 3.3.1_806 3.3.2_818 Y ignored
4/38 AppCleaner appcleaner 3.4 3.4 Y ignored
5/38 Github Atom atom 1.15.0 1.15.0 Y ignored
6/38 BetterZipQL betterzipql latest latest
7/38 Boom boom 1.6,1490693621 1.6,1490693621
8/38 CheatSheet cheatsheet 1.2.7 1.2.7
9/38 Cyberduck cyberduck 5.4.0.23761 5.4.0.23761
10/38 Dropbox dropbox 21.4.25 latest Y ignored
This is a list of apps installed on an Mac, 1 line per app.
If the app is outdated ('current' != 'latest'), I keep the line and make an object out of it for later treatement.
I came up with a dirty -yet working- solution :
function parseBrewCUArray(array) {
var toUpdate = [];
var lines = array.split('\n');
//remove useless lines
lines = lines.slice(3);
for (var i=0; i<lines.length; i++) {
splittedLine = lines[i].split(/[ ]{2,}/);
if (splittedLine[3] != splittedLine[4]) {
toUpdate.push(splittedLine)
console.log(splittedLine);
}
}
}
But there must be a very much better solution out there! Can someone optimize this a bit, making this piece of code more beautiful?