r/learnjavascript • • Feb 14 '17

Learn JavaScript With Interactive Challenges

https://edabit.com/explore
66 Upvotes

15 comments sorted by

View all comments

2

u/Pantstown Feb 14 '17

This is pretty great. Much better than other sites of this variety that I've tried.

My one gripe is that when I click "Check", and I pass all test cases, it saves that solution to the "Solutions" tab. The problem is when I click "Check", there is usually a bit of clean up I would like to do. Rather than auto-saving, maybe give the user a chance to re-factor and manually save as a solution?

For example, my saved solution for "Merge Two Arrays" has a bunch of console.logs:

function mergeArrays(a, b) {
  const rest = b.length > a.length ? b.slice(a.length) : [];

  return a.reduce((out, val, idx) => out.concat(val, b[idx]), [])
    .concat(rest)
    // filter out `undefined`s
    .filter(v => v);
}

console.log('out: ', mergeArrays(["a", "b", "c", "d", "e"], [1, 2, 3, 4, 5]));
console.log('~~~~~~~~~~');
console.log('out: ',mergeArrays(["e"], [1, 2, 3, 4, 5, 6, 7]));
console.log('~~~~~~~~~~');
console.log('out: ',mergeArrays([1, 2, 3, 4, 5, 6, 7], ["e"]));

But my finished answer actually looks more like:

function mergeArrays(a, b) {
  // only need to add rest if b is longer than a.
  const rest = b.length > a.length ? b.slice(a.length) : [];

  return a.reduce((out, val, idx) => out.concat(val, b[idx]), [])
    .concat(rest)
    // filter out `undefined`s
    .filter(v => v);
}

2

u/memystic Feb 14 '17

Yeah this is something I thought hard about during development. I'm thinking the simplest way would be to do check and then if it passes all tests, change button text to "submit". Do you think that would confuse anyone?

2

u/Pantstown Feb 15 '17

I think that would be better, maybe with a little explanation that the user can submit whenever she is ready.

All tests passed!

You can submit your answer whenever you're ready.

Something like that ¯_(ツ)_/¯

Also, gotta get some harder challenges on there! 😛