In: Computer Science
function cal_modes(list) { var result = []; var maxCount = 0; for (var i = 0; i < list.length; i++) { var count = 0; for (var j = 0; j < list.length; j++) { if (list[i] === list[j]) { count++; } } if (count > maxCount) { maxCount = count; } } for (var i = 0; i < list.length; i++) { var count = 0; for (var j = 0; j < list.length; j++) { if (list[i] === list[j]) { count++; } } if (count === maxCount) { var found = false; for (var k = 0; k < result.length; k++) { if (result[k] === list[i]) { found = true; } } if (!found) result.push(list[i]); } } return result; } console.log(cal_modes([3,4,5,5])); console.log(cal_modes([8.9, 1, 1])); console.log(cal_modes([2.5, -2, -2, 2.5])); console.log(cal_modes([3,3,4,4])); console.log(cal_modes([3,4,5])); console.log(cal_modes(["hi", "what", "where", "hi"]));