[JavaScript] 2126. Destroying Asteroids
\n---\n\nWeekly Contest 274\n  - Q1 answer\n    - https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/discuss/1661296/JavaScript-2124.-Check-if-
\n---\n\n**Weekly Contest 274**\n  - **Q1** answer\n    - https://leetcode.com/problems/check-if-all-as-appears-before-all-bs/discuss/1661296/JavaScript-2124.-Check-if-All-A\'s-Appears-Before-All-B\'s\n- **Q2** answer\n  - https://leetcode.com/problems/number-of-laser-beams-in-a-bank/discuss/1661353/javascript-2125-number-of-laser-beams-in-a-bank\n- **Q3** answer\n  - https://leetcode.com/problems/destroying-asteroids/discuss/1661395/JavaScript-2126.-Destroying-Asteroids\n  - **below**\n    - In the contest, thought Q3 needs an optimal solution, but after 20 mins changed to below linear solution\n      - 20 mins costed lot of ranks\n- **Q4** answer - **C++ & JavaScript**\n  - https://leetcode.com/problems/maximum-employees-to-be-invited-to-a-meeting/discuss/1664868/C%2B%2B-return-max-(-maxCycleLength-sumOfMaxCycle2ChainLengths-)\n\n---\n\nHope it is simple to understand.\n\n---\n\n```\nvar asteroidsDestroyed = function (mass, asteroids) {\n    let n = asteroids.length;\n    asteroids.sort((a, b) => a - b);\n\n    let asteroidDestroyed = 0;\n    for (let asteroidMass of asteroids) {\n        if (asteroidMass > mass) {\n            break;\n        }\n        mass += asteroidMass;\n        asteroidDestroyed++;\n    }\n    return asteroidDestroyed === n;\n};\n```\n\n---\n
['JavaScript']