Get the most frequent element in an array
I have an employee appraisal form. There are 9 objectives and each objective has 5-16 sub-objectives where the 'rater' will rate the employee for that task as Not Applicable, Not Met, Met, or Exceeded. Each objective will have it's own "Score".
I am looking for a javascript to look at the list of items within the objective and display the most selected option.
For example, Objective 1 has 6 sub-objectives.
- The dropdown fields = Objective 1 Rating.
- The field to display the answer = Score 1.
- 1 Not Applicable
- 1 Not Met
- 3 Met
- 1 Exceeded
"Score 1" should display "Met".
Also, in the event that there is a tie between 2 answers I'll need some logic on that.

I have already tried doing if, else if statements which worked to some extent but wasn't foolproof. I also tried a switch statements but couldn't get out of a syntax error.
I just came across these scripts that will do what I've been looking for but I don't know where I put my field name.
Option 1: getting a syntax error "missing ; before statement 2, line 3
function findhighestOccurenceAndNum(Objective1Rating) {
let obj = {};
let maxNum, maxVal;
for (let v of a) {
obj[v] = ++obj[v] || 1;
if (maxVal === undefined || obj[v] > maxVal) {
maxNum = v;
maxVal = obj[v];
}
}
console.log(maxNum + ' has max value = ' + maxVal);
}
findhighestOccurenceAndNum(['Not Applicable', 'Not Met', 'Met', 'Exceeded']);
Option 2:
function modeString(array) {
if (array.length == 0) return null;
var modeMap = {},
maxEl = array[0],
maxCount = 1;
for (var i = 0; i < array.length; i++) {
var el = array[i];
if (modeMap[el] == null) modeMap[el] = 1;
else modeMap[el]++;
if (modeMap[el] > maxCount) {
maxEl = el;
maxCount = modeMap[el];
} else if (modeMap[el] == maxCount) {
maxEl += "&" + el;
maxCount = modeMap[el];
}
}
return maxEl;
