Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
2019-07-18 Dev.to challenge
const makeRun = (v, {ofLength = 1} = {}) => Array.from({length: ofLength}, () => v).join("");
const hasTripleTrouble = (triple, double) => {
const [tripleStr, doubleStr] = [triple, double].map(v => String(v));
return (Array.from({length: 10}, (_, idx) => idx)
.some(digit => (tripleStr.indexOf(makeRun(digit, {ofLength: 3})) > -1
&& doubleStr.indexOf(makeRun(digit, {ofLength: 2})) > -1)));
}
const testCases = [
{ args: [123, 12345], result: false },
{ args: [1222245551, 1554223], result: true },
{ args: [451999277, 41177722899], result: true },
{ args: [1222345, 12345], result: false },
{ args: [12345, 12345], result: false },
{ args: [666789, 12345667], result: true },
];
const testAllCases = (fn, cases) =>
cases.map(({args, result}) => [`${args} -> ${result}`, fn(...args) === result])
.filter(([_, pass]) => !pass);
const failures = testAllCases(hasTripleTrouble, testCases);
if (failures.length > 0) {
throw new Error(JSON.stringify(failures), 2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.