bigbluebutton-Github/bigbluebutton-html5/imports/utils/caseInsensitiveReducer.js

17 lines
461 B
JavaScript
Raw Normal View History

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;