JSFiddle - React, Tailwind, and code Playground

by kidmenot

JavaScript

Array.prototype.contains = function(obj) {
    var i = this.length;
    while (i--) {
        if (this[i] == obj) {
            return i;
        }
    }
    return false;
}

var sorted = ['7', '8', '9', 't', 'j', 'q', 'k', 'a']

function check(arr) {
    index = sorted.contains(arr[0])
    if (index === false) {
        return false;
    }
    count = 1
    for (var i = 1; i < 4; i++) {

        sortedIndex = index + i > sorted.length ? index + i - sorted.length : index + i
        if (sorted[sortedIndex] == arr[i]) count++;
    }
    if (count == 4) {
        return true;
    }
    return false;
}

console.log(check(['j','q','k','a']))