r/webdev • • Feb 20 '17

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

https://edabit.com/explore
205 Upvotes

36 comments sorted by

View all comments

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 :)

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?