1
var numFriendRequests = function (ages) {2
const count = new Array(121).fill(0);4
ages.forEach((age) => count[age]++);6
let res = 0; // total friend request sent7
let tot = 0; // cumulative count of people so far9
for (let i = 0; i <= 120; i++) {10
if (i > 14 && count[i] != 0) {11
const limit = Math.floor(0.5 * i) + 7;12
const rest = tot - count[limit];14
res += count[i] * rest; // current age group send friend request to other people who are within their limit15
res += count[i] * (count[i] - 1); // current age group send friend request to each other