JSFiddle - React, Tailwind, and code Playground

by craigm

HTML

<script src="http://documentcloud.github.com/underscore/underscore-min.js"></script>
<script src="http://code.jquery.com/qunit/git/qunit.js"></script>
<link rel="stylesheet" href="http://code.jquery.com/qunit/git/qunit.css">
<h1 id="qunit-header">Underscore Tests</h1>
<h2 id="qunit-banner"></h2>
<div id="qunit-testrunner-toolbar"></div>
<h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol>
<div id="qunit-fixture">test markup, will be hidden</div>

JavaScript

// Testing Underscore.js Collection Functions
(function() {
    $(function() {
        var data = [
            {
                  product: 'Book',
                  amt: 2
            },
            {
                  product: 'Music',
                  amt: 1
            },
            {
                product: 'Movie',
                amt: 3
            }
        ];

        module('Collections');
        test('_.reduce', function() {
            equal(_.reduce(data, function(sum, item) {
                return sum + item.amt;
            }, 0), 6);
        });

        test('_.select', function() {
            var val = _.select(data, function(item) {
                return item.amt > 1;
            });

            ok(val);
            equal(val.length, 2);
            deepEqual(val[0], {
                product: 'Book',
                amt: 2
            });
            deepEqual(val[1], {
                product: 'Movie',
                amt: 3
            });
        });

        test('_.reject', function() {
            var val = _.reject(data, function(item) {
                return item.amt > 1;
            });

            ok(val);
            equal(val.length, 1);
            deepEqual(val[0], {
                product: 'Music',
                amt: 1
            });
        });

        test('_.include (by ref)', function() {
            var item = data[0];
            ok(_.include(data, item));
        });

        test('_.include (by val)', function() {
            ok(!(_.include(data, {
                product: 'Book',
                amt: 2
            })));
        });

        test('_.pluck', function() {
            var val = _.pluck(data, 'product');
            ok(val);
            ok(val.length);
            equal(val[0], 'Book');
            equal(val[1], 'Music');
            equal(val[2], 'Movie');
        });

        test('_.max', function() {
            deepEqual(_.max(data, function(item) {
                return item.amt;
     ...