JavaScript | Beat 96% | (^__^)
Bring your coffee and come enjoy with me and javascript\n\n\n# steps of my solution\nFirst I initialized an empty array called arr, a variable called sum to zer
# Bring your coffee and come enjoy with me and javascript\n![download (2).jfif](https://assets.leetcode.com/users/images/e688c60a-ee0d-41b3-933c-2bd25d5a32a5_1680464132.7804177.jpeg)\n\n# steps of my solution\nFirst I initialized an empty array called ```arr```, a variable called ```sum``` to zero, and a variable called ```check``` to zero.\n```\nconst arr = []\nlet sum = 0\nlet check = 0\n```\nI sorted array ```nums``` in ascending order using the ```sort``` function.\n``` nums.sort((a, b) => a - b)```\n\nThen, I looped through each query in the ```queries``` array using a ```for``` loop. For each query, the ```sum``` and ```check``` variables are reset to zero.\n\nThe function then loops through each number in the ```nums``` array using another ```for``` loop.\n\nFor each number, the number is added to the ```sum``` variable. If the resulting sum is less than or equal to the current query, the ```check``` variable is incremented by 1. If the sum is greater than the current query, the inner loop breaks and moves to the next query.\n\nFinally, the final value of ```check``` is added to the ```arr``` array using the ```push``` function, and the function returns ```arr``` after all queries have been processed.\n\n# Have fun with my code (^___^)\n```\n/**\n * @param {number[]} nums\n * @param {number[]} queries\n * @return {number[]}\n */\nconst answerQueries = (nums, queries) => {\n    const arr = []\n    let sum = 0\n    let check = 0\n    nums.sort((a, b) => a - b)\n    for (let i = 0; i < queries.length; i++) { \n        sum = 0; check = 0\n        for (let j = 0; j < nums.length; j++) { \n            sum += nums[j]\n            if (sum <= queries[i]) check += 1\n            else break\n        }\n        arr.push(check)\n    }\n    return arr\n};\n```
['JavaScript']