Destroying astroids in a simple way
Intuition\n Describe your first thoughts on how to solve this problem. \nThe issue in hand makes you think about how to find these astroids that are smaller tha
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\nThe issue in hand makes you think about how to find these astroids that are smaller than the current size, it\'s not that difficult on first glance, but in-order not to overdo the loops, i have to think of the different ways to find a smaller sized astroid than my current size.\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\nInstead of having todo multiple loops throughout i make it much more simple by first making the array sorted, that way i can break very early on to see if it\'s even possible for the astroid to destroy everything.\n\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n**O(log(n) + n)**\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n**O(2n)**\n\n# Code\n```\n/**\n * @param {number} mass\n * @param {number[]} asteroids\n * @return {boolean}\n */\nlet asteroidsDestroyed = (mass, astroids) => {\n\tconst sorted = astroids.sort((a, b) => a - b);\n\n\tfor(const astroid of sorted) {\n\t\tif (mass < astroid) return false;\n\t\tmass += astroid;\n\t}\n\n\treturn true;\n}\n\n\n```
['JavaScript']