Published
Edited
Dec 4, 2019
1 star
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
function isValidPassword(n) {
let hasRepeatingDigits = false;
let prevDigit = Infinity;
for (let digit of digitIterator(n)) {
if (digit > prevDigit) {
return false;
}
hasRepeatingDigits = hasRepeatingDigits || digit === prevDigit;
prevDigit = digit;
}
return hasRepeatingDigits;
}
Insert cell
Insert cell
Insert cell
Insert cell
function isValidPassword2(n) {
let has2RepeatingDigits = false;
let repeatCount = 0;
let prevDigit = Infinity;
for (let digit of digitIterator(n)) {
if (digit > prevDigit) {
return false;
}
if (digit === prevDigit) {
repeatCount++;
} else {
if (repeatCount === 1) {
has2RepeatingDigits = true;
}
repeatCount = 0;
}
prevDigit = digit;
}
return repeatCount === 1 || has2RepeatingDigits;
}
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more