JSFiddle - React, Tailwind, and code Playground
HTML
<script src="http://underscorejs.org/underscore-min.js"></script>
JavaScript
//open a console to see the results
function test(seq,expected) {
var res=isSequence(seq);
if (res===expected)
console.log( seq.join(',')+" : "+expected+" as expected");
else
console.log( seq.join(',')+" : fail");
}
function isSequence(seq) {
var sorted = ['7','8','9','t','j','q','k','a'], l=seq.length, i, ix;
if (l===0) return true;
ix=_.indexOf(sorted, seq[0]);
if (ix===-1) return false;
if (ix>sorted.length-l) return false;
for (i=1;i<l;i++) {
if ( sorted[ix+i]!==seq[i] )
return false;
}
return true;
}
var cards = [{card:'h7'},{card:'c8'},{card:'h9'},{card:'st'}]
test( _.map(cards, function(obj) {
return obj.card.charAt(1);
}), true );
test(['7','8','9','t'] , true);
test(['j','q','k','a'] , true);
test(['7','8','k','a'] , false);
test(['j','k','7','a'] , false);
test(['k','a','q'] , false);
test(['x'] , false);