JSFiddle - React, Tailwind, and code Playground

by tonytlwu

HTML

<h1>Test Results</h1>
<ul>
</ul>

CSS

* { font-family: sans-serif; line-height: 150% }
li { margin-bottom: 20px }
li.success { color: green }
li.error { color: red }
li code { font-family: monospace; font-weight: bold; }

JavaScript

// ------------------------------------------
// FILL IN YOUR ANSWERS HERE AND CLICK RUN!
// TIME TAKEN: x MINUTES
// ------------------------------------------

function addOne(number) {
  const int = parseInt(number.join(""));
  return (int+1).toString().split("");
}

// --------------------------------------------
// TESTS BELOW - PLEASE ADD YOUR OWN TEST CASES
// --------------------------------------------

expect('addOne([5, 1, 2])', addOne([5, 1, 2]), [5, 1, 3]);

// ------------------------------------------

function compareArrays(arr1, arr2) {
    return $(arr1).not(arr2).length == 0 && $(arr2).not(arr1).length == 0;
}

function expect(name, a, b) {
  if (a !== b && !(a instanceof Array && b instanceof Array && compareArrays(a, b))) {
    $('ul').append('<li class="error">Testing <code>' + name + '</code> ...<br />Error: <code>' + a + '</code> is the wrong answer</li>');
  } else {
    $('ul').append('<li class="success">Testing <code>' + name + '</code> ...<br>Right: <code>' + a + '</code> is the right answer</li>');
  }
}