I've read some posts where duplicates are removed from an array. For example, an array with "one", "one", "two", "three" will return "one", "two", "three" using the code I've found in some posts. I need to remove both values so "one", "one", "two", "three", will return "two", "three". I'm parsing a file and searching for items based on a regular expression. Here's what I have for code. There are times though where there is duplicate data in the file I'm parsing. I need to remove that data.
function parseText(text)
{
var records = text.match(fileRegex);
var fileArray = [];
if (records != null) {
records.forEach(function (element, index, array) {
var matches = elementRegex.exec(element);
if (matches != null) {
var year = matches[parseSettings.ParseYearPosition];
if (year == 2)
{
year = "20" + year;
}
var journalDate = new Date(year,
matches[parseSettings.ParseMonthPosition] - 1,
matches[parseSettings.ParseDayPosition],
matches[parseSettings.ParseHourPosition],
matches[parseSettings.ParseSecondPosition], 0, 0);
var file = {
Id: null,
ImportDate: moment(importDate).format(),
JournalDate: moment(journalDate).format(),
TraceNumber: parseInt(matches[parseSettings.ParseTraceNumberPosition]),
Amount: parseFloat(matches[parseSettings.ParseAmountPosition]),
Deleted: false,
Dirty: true
};
fileArray.push(file);
}
});
deferred.resolve(fileArray);
}