r/webdev • • Feb 20 '17

Learn JavaScript With Interactive Challenges X-Post /r/JavaScript

https://edabit.com/explore
205 Upvotes

36 comments sorted by

17

u/memystic Feb 20 '17

I really hope some people find this to be a fun tool. I spent a little over five months building it by myself.

Before anyone asks, yes, the backend currently supports other languages! Specifically:

  • C

  • C#

  • C++

  • Elixir

  • F#

  • Haskell

  • Java

  • JavaScript

  • Objective-C

  • OCAML

  • Php

  • Python

  • Ruby

  • Rust

  • Swift

Once I’ve smoothed out the rough edges and squashed some bugs, I’ll begin working on rolling other languages out. Also, the challenges right now are rather easy BUT the system allows anyone to publish their own challenges. So if you want harder/more challenges, by all means please help out! :)

3

u/tallahasseenaut Feb 21 '17 edited Feb 21 '17

Cool! just created a challenge … EDIT: another and another. I'm really enjoying this :)

2

u/memystic Feb 21 '17

Woot! Finally I can play with my creation!

1

u/elingeniero Feb 21 '17
function flattenArray(arr) {
  if (!arr) return [];
  return arr
  	.reduce((acc, x) => {
      if (Array.isArray(x)) return acc.concat(flattenArray(x));
      if (typeof x === 'function') return acc.concat(x());
      return acc.concat(x);
    }, []);
}

2.

function isBalanced(string) {
  if (!string) return undefined;
  if (string.length % 2 !== 0) return false;
  const bracketPairs = {
    '(': ')',
    '[': ']',
    '{': '}',
  };
  for (let i = 0; i < string.length / 2; i ++) {
    if (bracketPairs[string[i]] !== string[string.length - i - 1]) return false;
  }
  return true;
}

3.

function isAnagram(s1, s2) {
  return s1.toLowerCase().split('').sort().join('') ===
    s2.toLowerCase().split('').sort().join('');
}

What do I win?

1

u/memystic Feb 20 '17 edited Feb 20 '17

Highjacking my comment to get feedback on a feature I'm working on right now. Here's a screenshot. Any user can create their own "group", which is essentially a chatroom with a private leaderboard. So you could, for example, invite your friends and compete with them to see who can get the most XP and help each other out in the chat area. The group can be either public or private: public groups can be joined by anyone and private groups need the owner to add them. Anyone will be able to create a group just like anyone can publish a challenge.

1

u/rs1712 Feb 20 '17

Can we get, code-golf added as well, more fun for experienced people :D

1

u/memystic Feb 21 '17

code-golf

Can you explain what code-golf is? I'm unfamiliar.

3

u/[deleted] Feb 21 '17

its basically trying to minimize the code size for a project. in effect: try and use as many arcane tricks as you can to save bytes (and effectively obfuscate your code).
example

1

u/rs1712 Feb 22 '17

askuriel did explain below, but its basically challenge to create the shortest code.

Also still getting the react/meteor errors http://imgur.com/a/Ww7iu

4

u/SteveB0X Feb 20 '17

I just want to say, this is a really great site. The challenges are very approachable for me, which is something I can't say about the hackerranks and leetcodes. It's exactly what I need right now.

However, I'm having trouble getting my first challenge to submit. My code is printing out the answers to the console, but the test is not accepting them. I.e.,

Duck
Expected: 'Duck', instead got: undefined
3
Expected: 3, instead got: undefined
undefined
Test Passed: Value == undefined
true
Expected: true, instead got: undefined
null
Expected: null, instead got: undefined    

Here is my solution (spoiler)

So to me, it seems like I have the correct code, but the interpreter is not seeing my answers. What is the correct way to print the output so it is accepted?

3

u/memystic Feb 20 '17

Works fine for me. Go to this challenge and paste this into the Code tab:

function getLastItem(arr) {
  return arr[arr.length - 1]
}

Click the "Check" button. Should work fine.

2

u/SteveB0X Feb 20 '17

Oh I get it now! I'm so used to console.log-ing everything, when all I needed to do was return my lastItem variable by itself.

Thanks!

2

u/memystic Feb 20 '17

No problem, if you have any other questions just PM me or email [email protected]

1

u/memystic Feb 20 '17

When I click that link reddit gives me an error... Looking at the stats, I'm not seeing anyone else having issues doing Checks / Submit Finals. Can you PM me the code without spoiler thingys?

1

u/SteveB0X Feb 20 '17

The spoiler show the code in a tooltip when you hover over the link. I'll pm you the code too just in case

3

u/el_lyss Feb 20 '17 edited Feb 20 '17

You should definitely work on improving load speed. It took more than 10s to load the site the first time for me.

Also you use a meteorjs, right? Well, you should definitely work on SEO, because right now Google thinks your site is literally empty.

1

u/memystic Feb 20 '17

Normally it's very fast but has been getting lots of traffic this morning, hence the slowdown. I've got the frontend on Galaxy and the database on mLab. If traffic stays consistently strong, I'll upgrade to a dedicated mLab server as that seems to be the bottleneck. As for SEO, I know and will be implementing server side rendering next week. Just not a big priority right now.

1

u/rs1712 Feb 20 '17

Running really slow, and meteorjs is throwing alot of errors too

1

u/memystic Feb 20 '17

Can you try again in another browser or clear your cache? I just upped my CPU significantly. Should be fast-ish now.

1

u/rs1712 Feb 20 '17

It got faster about 15 mins after I posted

3

u/[deleted] Feb 20 '17 edited Feb 20 '17

This is great! Definitely something I would add as a homepage.

One suggestion or feature I would like is, if two submitted solutions are exactly the same, to remove the least upvoted one so it doesn't clog up the list of solutions. Other than that, thank you for building this!

1

u/memystic Feb 20 '17

Yes, I'm working on some code that will minify / remove comments and then combine similar code. This will solve the issue.

3

u/forhlol Feb 21 '17

What are your thoughts on logging in using GitHub? Any chance this will be implemented? I think a lot of people who would use a site like this, may want to login using their GitHub accounts. Just a thought. Great work!

1

u/masterm Feb 20 '17

Was cool until I had to log in to try it. Don't let me do half the thing then try to get me to login

12

u/memystic Feb 20 '17

Code is being executed on my servers. Until I'm sure everything is secure (I just launched this), you'll just have to deal with it.

2

u/evohans Feb 20 '17

I'm sold, time to play.

1

u/roly768 Feb 20 '17

Awesome tool you've built here, thank you! My only suggestion would be in regards to the interface. When working on a challenge it would be nice to have the instructions and code visible at the same time so that I don't have to toggle back and forth if I get stuck or need clarification.

1

u/Badrush Feb 20 '17

Hey I just used your site to solve 6 problems and it was great, easy to use. I will keep using it :)

My suggestions:

  • Make the error console easier to read

  • Maybe show my runtime and let me see how it compares to other

1

u/rs1712 Feb 20 '17

So I came across this challenge... couldn't resist.

http://i.imgur.com/m8NLM0m.png

1

u/Sr_Geckko Feb 21 '17

WOW awesome dude great job!

1

u/JaniRockz Feb 21 '17

I love it.

Only minor annoyance I encountered was that after basically finishing a task you cant test your code again (to improve it for example) without finishing the whole task (red button).

1

u/[deleted] Feb 22 '17

Many many many many many thanks!

0

u/[deleted] Feb 20 '17

[deleted]

1

u/memystic Feb 20 '17

Thanks! The solutions are locked until completion. Once you complete the challenge, you'll see all the solutions and can upvote/downvote them.

0

u/[deleted] Feb 21 '17

[deleted]

2

u/memystic Feb 21 '17

I totally agree. The solutions tab is my most underdeveloped feature. Soon this will be implemented:

  • Similar code will be combined.

  • Rank solutions by efficiency.

  • Length (for finding those nice one liners).

  • Etc