[CodeKata]予算


リンク
  • https://programmers.co.kr/learn/courses/30/lessons/12982
  • 私の答え
    function solution(d, budget) {
      const arr = [];
      const ascendingD = d.sort((a, b) => a - b);
      for (let num of ascendingD) {
        budget -= num;
        if (budget >= 0) {
          arr.push(num);
        } else {
          return arr.length;
        }
      }
      return arr.length;
    }