Super Easy Approach using a while loop -- IN JS :)
Intuition\nWhat you would need:\nBasic Understanding of the mechanism of iterting an array\nFamiliarity with sort method via arrow function\nA bit of Focus :) \
# Intuition\nWhat you would need:\nBasic Understanding of the mechanism of iterting an array\nFamiliarity with sort method via arrow function\nA bit of Focus :) \n\n# Approach\n- Initialize a counter variable called "count" to keep track of the number of boats needed to carry all the people.\n- Initialize a variable called "n" to the length of the people array.\n- Initialize a variable called "i" to 0.\n- Sort the people array in non-increasing order using the Array.sort() method and a comparison function that sorts in descending order.\n- While "i" is less than "n", do the following:\n1. Check if the heaviest person can fit with the lightest person on the boat. If they can, move to the next lightest person by decrementing "n".\n2. Load the heaviest person on a boat by incrementing "i".\n3. Increment the "count" variable to keep track of the number of boats used.\n- After the loop ends, return the "count" variable.\n\n# Complexity\n- Time complexity:\nO(nlogn)\n\n- Space complexity:\n- O(1)\n# Code\n```\n/**\n * @param {number[]} people\n * @param {number} limit\n * @return {number}\n */\nconst numRescueBoats = function(people, limit) {\n  let count = 0;\n  let n = people.length;\n  let i = 0;\n  \n  // Sort the people array in non-increasing order\n  people.sort((a, b) => b - a);\n  while (i < n) {\n    if (people[i] + people[n - 1] <= limit) {\n      n--;\n    }\n    // Load the heaviest person on a boat\n    i++;\n    count++;\n  }\n\n  return count;\n};\n```
['JavaScript']