Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="banner text-center">
  <span class="control mirror">mirror</span>
  <span>&nbsp;- </span>
  <span>consecutive : </span>
  <span class="control consecutive-full">full</span>
  <span>, </span>
  <span class="control consecutive-hour">hour</span>
  <span>, </span>
  <span class="control consecutive-minute">minute</span>
  <span>&nbsp;- </span>
  <span class="control same">same</span>
  <span>&nbsp;- </span>
  <span class="control binary">like binary</span>
  <span>&nbsp;- </span>
  <span class="control four-digits">4 different digits</span>
  <span>&nbsp;- </span>
  <span class="control favorite">my favorites</span>
  <span>&nbsp;- </span>
  <span class="control odd">odd</span>
  <span>&nbsp;- </span>
  <span class="control even">even</span>
</div>

<div class="text-center container">
  <div class="datetime prototype hidden">
    <span class="hour"></span>
    <span>:</span>
    <span class="minute"></span>
  </div>
</div>
            
          
!
            
              body {
  background-color: #fff;
}

div.container {
  padding-top: 25px;
}

div.datetime {
  display: inline-block;
  
  margin: 2px;
  padding: 2px 4px;
  font-weight: 400;
  border: 2px solid #000;
}

div.datetime:hover, 
div.datetime.selected,
div.datetime.selected-c-f,
div.datetime.selected-c-h,
div.datetime.selected-c-m
{
  color: #fff;
  background-color: #000;
}

div.banner {
  position: fixed;
  top: 0;
  font-size: 0;
  width: 100%;
  height: 20px;
  background-color: #000;
}

div.banner span.control:hover {
  cursor: pointer;
}

div.banner *::selection {
  background-color: transparent;
}

div.banner span {
  color: #fff;
  font-size: 14px;
  display: inline;
}

div.banner span.control.selected {
  text-decoration: underline;
}
            
          
!
            
              function generateHoursMap() {
  var h = 0;
  var hoursMap = [];

  while (h < 24) {
    hoursMap = hoursMap.concat(generateMinutesMap(h));

    h = h + 1;
  }

  return hoursMap;
}

function generateMinutesMap(h) {
  var m = 0;
  var minutesMap = [];
  var hour = getFormattedString(h);

  while (m <= 59) {
    var minute = getFormattedString(m);

    minutesMap.push({
      minute: minute,
      hour: hour,
      criteria: resolveCriteria(hour, minute)
    });

    m = m + 1;
  }

  return minutesMap;
}

function resolveCriteria(hour, minute) {
  var isMirror = function(h, m) {
    return h[0] === m[1] && h[1] === m[0];
  };
  
  var isFavorite = function(sequence) {
    var found = false;
    var favorites = ['0137', '1137', '1337', '1418', '1620', '2112', '2342', '0042', '1814', '0033'];
    
    favorites.forEach(function(favorite) {
      favorite === sequence && (found = true);
    });
    
    return found;
  };
  
  var isBinary = function(sequence) {
    for (i = 0; sequence[i]; i = i + 1) {
      if (sequence[i] != '0' && sequence[i] != '1') {
        return false;
      }
    }
    
    return true;
  };
  
  var hasDiffenrentDigits = function(sequence) {
    var encountered = '';
    
    for (i = 0; sequence[i]; i = i + 1) {
      if (encountered.indexOf(sequence[i]) != -1) {
        return false;
      }
      
      encountered = encountered + sequence[i];
    }
    
    return true;
  };
  
  var resolveConsecutive = function(h, m) {
    return {
      full: isConsecutive(h + m),
      hour: isConsecutive(h),
      minute: isConsecutive(m)
    };
  };
  
  var isEven = function(number) {
    return number % 2 === 0;
  };
  
  return {
    even: isEven(hour + minute), // I know it could be done using one variable...
    mirror: isMirror(hour, minute),
    binary: isBinary(hour + minute),
    favorite: isFavorite(hour + minute),
    consecutive: resolveConsecutive(hour, minute),
    differentDigits: hasDiffenrentDigits(hour + minute),
    same: hour === minute
  };
}

function isConsecutive(sequence) {
  for (i = 0; sequence[i]; i = i + 1) {
    if (sequence[i + 1] && (sequence[i + 1] - sequence[i] != 1)) {
      return false;
    }
  }

  return true;
}

var hoursMap = generateHoursMap();

displayHours(hoursMap);
//console.log(hoursMap);

function printHours(hoursMap) {
  hoursMap.forEach(function(time) {
    console.log(
      getFormattedString(time.hour),
      ":",
      getFormattedString(time.minute)
    );
  });
}

function clonePrototype($prototype) {
  return $prototype.clone().removeClass("prototype hidden");
}

function displayHours(hoursMap) {
  var dateTimeContainer = $("div.container");
  var dateTimePrototype = $("div.datetime.prototype");

  hoursMap.forEach(function(time) {
    var newDateTimeBlock = clonePrototype(dateTimePrototype);

    newDateTimeBlock.find("span.hour").html(time.hour);
    newDateTimeBlock.find("span.minute").html(time.minute);

    newDateTimeBlock.toggleClass("odd", !time.criteria.even);
    newDateTimeBlock.toggleClass("even", time.criteria.even);
    newDateTimeBlock.toggleClass("same", time.criteria.same);
    newDateTimeBlock.toggleClass("mirror", time.criteria.mirror);
    newDateTimeBlock.toggleClass("binary", time.criteria.binary);
    newDateTimeBlock.toggleClass("favorite", time.criteria.favorite);
    newDateTimeBlock.toggleClass("four-digits", time.criteria.differentDigits);
    newDateTimeBlock.toggleClass("consecutive-full", time.criteria.consecutive.full);
    newDateTimeBlock.toggleClass("consecutive-hour", time.criteria.consecutive.hour);
    newDateTimeBlock.toggleClass("consecutive-minute", time.criteria.consecutive.minute);

    newDateTimeBlock.appendTo(dateTimeContainer);
  });
}

function getFormattedString(time) {
  return time < 10 ? "0" + time : time.toString();
}

$("span.control").on("click", function() {
  var that = $(this);
  var selected = that.hasClass("selected");
  var odd = that.hasClass("odd");
  var even = that.hasClass("even");
  var same = that.hasClass("same");
  var mirror = that.hasClass("mirror");
  var binary = that.hasClass("binary");
  var favorite = that.hasClass("favorite");
  var differentDigits = that.hasClass("four-digits");
  var fullConsecutive = that.hasClass("consecutive-full");
  var hourConsecutive = that.hasClass("consecutive-hour");
  var minuteConsecutive = that.hasClass("consecutive-minute");

  that.toggleClass("selected", !selected);

  odd && $("div.datetime.odd").toggleClass("selected", !selected);
  even && $("div.datetime.even").toggleClass("selected", !selected);
  same && $("div.datetime.same").toggleClass("selected", !selected);
  mirror && $("div.datetime.mirror").toggleClass("selected", !selected);
  binary && $("div.datetime.binary").toggleClass("selected", !selected);
  favorite && $("div.datetime.favorite").toggleClass("selected", !selected);
  differentDigits && $("div.datetime.four-digits").toggleClass("selected", !selected);
  fullConsecutive && $("div.datetime.consecutive-full").toggleClass("selected-c-f", !selected);
  hourConsecutive && $("div.datetime.consecutive-hour").toggleClass("selected-c-h", !selected);
  minuteConsecutive && $("div.datetime.consecutive-minute").toggleClass("selected-c-m", !selected);
});

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.

Console