DEV Community

Cover image for JavaScript Coding Challenges

JavaScript Coding Challenges

Florin Pop on March 15, 2019

When it comes to programming, I am a big fan of two things: JavaScript and Coding Challenges! And I can't be happier than when I'm able to combine ...
Collapse
 
learnbyexample profile image
Sundeep • Edited

heads up, you've got a typo - missing 'c' in Regular Brakets

I have a few beginner to intermediate level exercises for Python - you could translate them to Javascript if you are interested :)

I also have some resource links for practice ideas and sites - might help you get more challenges to solve

Collapse
 
mehdibenhemdene profile image
mehdibenhemdene

Suggested alternative solution for "Where do I belong" using Array.prototype.filter:

var array = [1, 2, 3, 4];

function getIndexToIns(arr, number) {
  let result = arr.sort().filter(el => el <= number).length;
  return result;
}

console.log(getIndexToIns(array, 8));
Enter fullscreen mode Exit fullscreen mode
Collapse
 
mehdibenhemdene profile image
mehdibenhemdene

Also a simple "Destroyer" implementation:

function destroyer(arr, ...params) {
  return arr.filter(el=>!params.includes(el));
}

Collapse
 
ramnewton profile image
Ram Newton
function destroyer(arr, ...params){
    params_set = new Set(params);
    return arr.filter(item => !(params_set.has(item)))
};
Enter fullscreen mode Exit fullscreen mode

.includes() does a linear search. Creating a set out of the parameters and using the .has() method will improve performance

Collapse
 
mattmacpherson profile image
Matt MacPherson

Check out Edabit; I think you'll like it.

Collapse
 
farxelemon profile image
Ricardo Pedroso

Thanks for the post, I had a lot of fun going through these exercises!

For the phone number one, I'll leave here my one line solution:

solution

Have a nice day :)

Collapse
 
deepakpal profile image
Deepak Pal

Good Post to read and thank for sharing the links

Collapse
 
florinpop17 profile image
Florin Pop

My pleasure! ☺️

Collapse
 
ali profile image
Haider Ali

Thank you so much for that , as a developer I think the only way to define you level is by solving coding challenges , hope we see some other challenges

Collapse
 
florinpop17 profile image
Florin Pop

This is what I’m planning to do! πŸ˜ƒ

Collapse
 
parshirahul profile image
Rahul Parshi

Nice idea and it will be helpful in interviews also as we can explain them more clearly..

Collapse
 
florinpop17 profile image
Florin Pop

Exactly! Very happy to help! ☺️

Collapse
 
borowskidaniel profile image
Daniel Borowski

Check out Coderbyte, lots of coding challenges and interview prep material!