JS Turn-Based Component

by Sam Fereday

HTML

<button id="start">
  Begin
</button>

JavaScript

console.clear();

/// ES6 and 7 all of this when done.
// My own brand of ramda (winging it) :o
var samda = {

  // Todd Motto foreach - https://github.com/toddmotto/foreach/blob/master/dist/foreach.js
  fe: function (collection, callback, scope) {
    
    if (Object.prototype.toString.call(collection) === '[object Object]') {
    
    	for (var prop in collection) {
        if (Object.prototype.hasOwnProperty.call(collection, prop)) {
          callback.call(scope, collection[prop], prop, collection);
        }
      }
    
    } else {
    
    	for (var i = 0, len = collection.length; i < len; i++) {
        callback.call(scope, collection[i], i, collection);
      }
    
    }
    
  },
  
  // Laymens chance
  flip: function() {
  	 return Math.round(math.random());
  },
  
  // Custom
  same: function(a, b) {
  	
    return a === b;
    
  },
  
  sameId: function(a, b) {

    return this.same(a, b);

  },

  valid: function(prop) {

    return this.notUndefined(prop) && this.notNull(prop);

  },

  // Undef or null checks
  notUndefined: function(a) {

    return typeof a !== 'undefined';

  },

  notNull: function(a) {

    return a !== null;

  },
  
  notNullOrUndefined: function(a) {
  
  	return this.valid(a);
  
  },

  // Type checks
  typeString: function(str) {

    return typeof str === 'string';

  },

  // Strings
  hasLength: function(str) {

    return this.typeString(str) && str.length > 0;

  },

  notNullOrEmpty: function(str) {

    return this.typeString(str) && this.hasLength(str);

  },
  
  // Arrays
  first: function(arr) {
  
  	return this.notEmpty(arr) ? arr[0] : [];
  
  },
  
  isArray: function(arr) {
  	return Array.isArray(arr);
  },
  
  notEmpty: function(arr) {
  	return this.isArray(arr) && arr.length > 0;
  },
  
  shuffle: function(array) {
  	
    if(!this.notEmpty(array))
    	return;
  
  	// https://bost.ocks.org/mike/shuffle/ (wip)
    var currentIndex = array.length, temporaryValue, randomIndex;

    // While...