function findMedian(data) {
// Sort the data in ascending order
data.sort((a, b) => a - b);
const n = data.length;
// If the number of data points is odd, return the middle value
if (n % 2 !== 0) {
return data[Math.floor(n / 2)];
} else {
// If the number of data points is even, return the average of the two middle values
const mid1 = data[n / 2 - 1];
const mid2 = data[n / 2];
return (mid1 + mid2) / 2;
}
}
// Example
const classData = [85, 92, 78, 95, 88];
const median = findMedian(classData);
console.log("Median:", median);
Cell In[21], line 1
function findMedian(data) {
^
SyntaxError: invalid syntax