const countArr = [
['XXX', 3],
['XXXXX', 6],
['XXXXXX', 9],
['XXX', 2]
];
const getCount = (arr, count = 4) =>
arr.map(itemL => (itemL[1] - itemL[0].length)).map((positiveN, i, arr) => {
if(positiveN < 0) {
return arr[i] = 0;
}
return positiveN;
}).reduce((accum, currentValue) => {
const result = parseInt(accum + currentValue);
return count - result;
});
console.log(getCount(countArr, 4)); //4 - 4 return 6
countArr.map(itemL => (itemL[1] - itemL[0].length)).map((positiveN, i, arr) => {
if(positiveN < 0) {
return arr[i] = 0;
}
return positiveN;
})