Untitled

mail@pastecode.io avatar
unknown
typescript
2 years ago
387 B
2
Indexable
Never
const data = {
  John: [70, 60, 80],
  Peter: [20, 30, 60],
  Jacob: [90, 90, 90],
};

function getGrading(data: Object) {
  const grading = {};
  for (const item in data) {
    const avg = data[item].reduce((a, b) => a + b) / data[item].length;
    grading[item] = [avg, avg > 60 ? 'Passed' : 'Failed'];
  }
  return grading;
}

const grading = getGrading(data);

console.log(grading);