Boats to Save People LeetCode solution in JavaScript
1/**2* @param {number[]} people3* @param {number} limit4* @return {number}5*/6var numRescueBoats = function (people, limit) {7people = people.sort((a, b) => a - b);89let left = 0;10let right = people.length - 1;11let res = 0;1213while (left <= right) {14if (people[left] + people[right] <= limit) {15res++;16right--;17left++;18} else if (people[right] <= limit) {19res++;20right--;21}22}2324return res;25};