Skip to content

Instantly share code, notes, and snippets.

@kerrishotts
Created July 20, 2019 04:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerrishotts/85214dd3fd0131283dc137d694930566 to your computer and use it in GitHub Desktop.
Save kerrishotts/85214dd3fd0131283dc137d694930566 to your computer and use it in GitHub Desktop.
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