Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Clear category for [old] Word Pattern by jdent
"use strict";
function checkCommand(pattern, command){
// Convert the command to binary
const binary = command
.replace(/[\d]/g, '0')
.replace(/[^\d]/g, '1');
const cmdAsNum = Number.parseInt(binary, 2);
return pattern === cmdAsNum;
}
var assert = require('assert');
if (!global.is_checking) {
assert.equal(checkCommand(42, "12a0b3e4"), true, "42 is the answer");
assert.equal(checkCommand(101, "ab23b4zz"), false, "one hundred plus one");
assert.equal(checkCommand(0, "478103487120470129"), true, "Any number");
assert.equal(checkCommand(127, "Checkio"), true, "Uppercase");
assert.equal(checkCommand(7, "Hello"), false, "Only full match");
assert.equal(checkCommand(8, "a"), false, "Too short command");
assert.equal(checkCommand(5, "H2O"), true, "Water");
assert.equal(checkCommand(42, "C2H5OH"), false, "Yep, this is not the Answer");
console.log("Coding complete? Click 'Check' to review your tests and earn cool rewards!");
}
June 5, 2017