Skip to content

Instantly share code, notes, and snippets.

@klauszhang
Last active November 13, 2017 07:21
Show Gist options
  • Save klauszhang/e2f4f64960557cb570a3fba2a7f2a809 to your computer and use it in GitHub Desktop.
Save klauszhang/e2f4f64960557cb570a3fba2a7f2a809 to your computer and use it in GitHub Desktop.
a validation
//1357 just a random number to get thing started
const sut = require('./index')(1357);
// should have 1000 elements
if (sut.size !== 1000) {
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 => {
sut.forEach(item => {
if (regex.test(item)) {
console.log(item);
console.error('something goes wrong...');
}
});
});
// should have no consecutive numbers
Array.from(sut).forEach(item => {
const numArray = item
.toString()
.split('')
.map(item => parseInt(item));
[0, 1, 2].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