In an attempt to minimize the objects within arrays that have a property "Title" containing any substring listed in a separate JSON file, I have been struggling with filtering the arrays based on the object's property. However, I believe using the reduce() method would be a more effective approach to achieve this.
The objective is to perform calculations only for objects that are not excluded. For instance, if an object has a Title property different from those specified (qa, quality assurance, software tester), it should be removed from the calculation.
I have been experimenting with different methods to accomplish this task but have not been successful. I think a better approach would be to modify the positionsArray by reducing the objects that should not be included in the calculation, and then perform the necessary calculations.
Here is the function I have been working on:
calculateSoftwareExperience: async function () {
fileToCurate.forEach(candidate => {
const positionsArray = candidate.softwareIndustryPositions;
console.log(positionsArray)
//const reducedArray = positionsArray.reduce(x => x.title)
//console.log(positionsArray)
if (Array.isArray(positionsArray) && positionsArray.length) {
// array exists and is not empty
positionsArray.forEach(position => {
let title = position.title;
if (titlesIncluded.some(x => title.includes(x))) {
console.log(title)
const firstFrom = positionsArray[positionsArray.length - 1].from;
const lastTo = positionsArray[0].to;
let diff = lastTo - firstFrom;
let days = (diff * 1000) / (60 * 60 * 24 * 1000) / 1000;
let months = Math.floor(days / 31);
//console.log(firstFrom, "to", lastTo, "diff = ", months);
candidate.softwareIndustryExp = months;
//console.log(months)
}
});
} else {
candidate.softwareIndustryExp = 0;
}
});
},
Output of positionsArray:
[
{
flagged: false,
from: 2019-10-31T23:00:00.000Z,
to: 2020-01-31T23:00:00.000Z,
title: 'junior manual tester'
},
{
flagged: false,
from: 2018-05-31T22:00:00.000Z,
to: 2019-09-30T22:00:00.000Z,
title: 'junior administrator'
},
{
flagged: false,
from: 2016-03-31T22:00:00.000Z,
to: 2016-03-31T22:00:00.000Z,
title: 'praktykant'
}
]
Input with specified substrings:
"titlesIncluded": [
"qa",
"quality engineer",
"qa automation",
"software tester",
"qa engineer"
],