Must be written in JavaScript. 4. [Problem Description] Amy, under her stress, decided to go to her department store aft

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

Must be written in JavaScript. 4. [Problem Description] Amy, under her stress, decided to go to her department store aft

Post by answerhappygod »

Must be written in JavaScript.
4.
[Problem Description]
Amy, under her stress, decided to go to her departmentstore after a long time and waste all her money shehad.
However, she can only buy 2 items and she must use allthe money she has to buy her items.
For example, if she has 10 money and the commodity shecan buy is [1, 2, 6, 7, 8],
She needs to buy a product with a price of 2 and aproduct with a price of 8 before she can spend all hermoney.
So, you just need to return [2,8] as aresult.
Always return results sorted in ascending order, withthe lowest number first.
[Restrictions]
- There is always only one possible way to spend all of themoney you have.
- You have no more than 2 and no more than 10000.
- The price of each product is between 1 and 10000.
[Input format]
- The money you have and the cost of a list of products you canbuy are given.
[Output Format]
- Please print the two sorted product prices in the form of anarray.
///
function solution(money, ZERO) {
var answer = [];
return answer;
}
//
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply