Solved Electronics Shop Algorithm with JavaScript from HackerRank

Dale Nguyen
1 min readMar 5, 2018

--

I’m just trying to solve all of them by using JavaScript.

If you want to read the detail of Electronics Shop challenge, please visit HackerRank website.

Here is the explanation for my JavaScript solution:

function getMoneySpent(keyboards, drives, s){
// Complete this function
let max = -1;

// I'm trying to get the total number of keyboard and drive
// then compare to the money.
for(let i = 0; i < keyboards.length; i++){
var temp = 0;
for(let j = 0; j < drives.length; j++){
if(keyboards[i] + drives[j] <= s){
temp = keyboards[i] + drives[j];
max = temp > max ? temp : max;
}
}
}

return max;
}

You can visit my git repository for more JavaScript solution, or if you can improve it, please leave a comment :)

https://github.com/dalenguyen/hackerrank-javascript

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Dale Nguyen
Dale Nguyen

Written by Dale Nguyen

✍️ Author 👨‍💻 Full Stack Engineer 👷 Indie Hacker 🔗 https://dalenguyen.me

Responses (1)

Write a response