bigbluebutton-Github/bigbluebutton-html5/imports/utils/caseInsensitiveReducer.js
2021-03-23 06:30:37 +00:00

17 lines
461 B
JavaScript

const caseInsensitiveReducer = (acc, item) => {
const index = acc.findIndex(ans => ans.key.toLowerCase() === item.key.toLowerCase());
if(index !== -1) {
if(acc[index].numVotes >= item.numVotes) acc[index].numVotes += item.numVotes;
else {
const tempVotes = acc[index].numVotes;
acc[index] = item;
acc[index].numVotes += tempVotes;
}
} else {
acc.push(item);
}
return acc;
};
export default caseInsensitiveReducer;