Skip to content

Instantly share code, notes, and snippets.

@klauszhang
Created November 13, 2017 20:06
Show Gist options
  • Save klauszhang/55db21356157204f0983023c1e830706 to your computer and use it in GitHub Desktop.
Save klauszhang/55db21356157204f0983023c1e830706 to your computer and use it in GitHub Desktop.
const getSolution = require('./dic-lookup');
const digit = 4;
const count = 1000;
const sut = getSolution(digit, count)();
// should have 1000 elements
if (sut.size !== count) {
console.log(sut.size);
console.error('something goes wrong...');
}
// should have no duplicate numbers
[
/11/,
/22/,
/33/,
/44/,
/55/,
/66/,
/77/,
/88/,
/99/,
/00/
].forEach(regex => {
Array.from(sut).forEach(item => {
if (regex.test(item)) {
console.log(item);
console.error('something goes wrong...');
}
});
});
// generate a list of digit count
const digitCountArr = Array.from(
new Array(digit)
);
// should have no consecutive numbers
Array.from(sut).forEach(item => {
const numArray = item
.toString()
.split('')
.map(item => parseInt(item));
digitCountArr.forEach((_, index) => {
if (
numArray[index] ===
numArray[index + 1] - 1
) {
console.log(item);
console.error('something goes wrong...');
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment