Skip to content

Instantly share code, notes, and snippets.

@klauszhang
Created November 13, 2017 10:20
Show Gist options
  • Save klauszhang/621f7b3ed4e987959a1ded03fe8773db to your computer and use it in GitHub Desktop.
Save klauszhang/621f7b3ed4e987959a1ded03fe8773db to your computer and use it in GitHub Desktop.
const {
generator,
getSolution
} = require('./refined');
const digit = 7;
const count = 10000;
const sut = getSolution(count)(
generator(digit)
)();
// 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