While working on my AngularJS app, I found myself iterating through a .csv file to perform element level validation. Since I couldn't find a suitable library in Angular, I decided to write custom JavaScript code to handle this scenario. Below is a sample of the data I'm working with (specifically interested in the first column CN and the 5th column NAME). My approach so far involves using if conditions to check the index of i, j, and store the values. Any suggestions or improvements would be greatly appreciated.
CN N ACTIVE TYPE NAME NO COM
USA 45 Engin Fed Anderson #10 NA
USA 46 Sports BB Kobe #1 NA
USA 32 Sports Soccer Kobe #17 NA
GER 30 Sports Soccer Gotze #12 NA
GER 27 Sports Soccer Ozil #18 NA
ITA 38 Sports Soccer Buffon #2 NA
Here's a snippet of the code:
for (var i = 0; i < file.length; i++ ){
var singleRowData = file[i].split(',');
singleRowData = singleRowData.filter(function(n){ return n != "" });
for (var j = 0; j < singleRowData.length; j++){
duplicateFunction(singleRowData, singleRowData[j], j, i);
}
}
function duplicateFunction (singleRowData, singleRowDataElement, singleRowDataElementIndex, singleRowDataIndex){
/*
handle the duplicates
*/
}
- If I come across the same values in the CN column for consecutive rows, then I want to check if there are duplicate values in the NAME column for those rows.
- If there are no duplicate NAME values for different rows with the same CN value, then no error should be thrown.
In the example data provided, an exception should be flagged on the 3rd row where CN=USA and NAME=Kobe, while the rest of the data should proceed without issues.