Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
Clear&Readable solution in Clear category for [old] Card Game by SaintDron
"use strict";
function cards(deck, hand) {
let card = 0;
for (let h of hand.sort((a, b) => a - b)) {
card = Math.max(++card, h);
if (card > deck || card > h + 1)
return false;
}
return true;
}
var assert = require('assert');
if (!global.is_checking) {
console.log('Example:')
console.log(cards(5, [2, 0, 1, 2]))
// These "asserts" are used for self-checking and not for an auto-testing
assert.equal(cards(5, [2, 0, 1, 2]), false)
assert.equal(cards(10, [9, 9, 6, 6]), true)
assert.equal(cards(10, [11]), false)
console.log("Coding complete? Click 'Check' to earn cool rewards!");
}
Sept. 23, 2018
Comments: