Skip to content

Instantly share code, notes, and snippets.

@jonataa
Created March 10, 2018 21:15
Show Gist options
  • Save jonataa/e68bda2e5c194ce73d42a0ca72232cbd to your computer and use it in GitHub Desktop.
Save jonataa/e68bda2e5c194ce73d42a0ca72232cbd to your computer and use it in GitHub Desktop.
function isBeatifulNumber(n, has = '4', hasnot = '9') {
const numberAsString = n.toString();
const hasFour = numberAsString.includes(has) === true;
const hasNine = numberAsString.includes(hasnot) === false;
return hasFour && hasNine;
}
const isBeatifulNumberHasThreeAndHasNotTwo = function (n) {
return isBeatifulNumber(n, '3', '2');
};
console.log(isBeatifulNumber(42) === true);
console.log(isBeatifulNumber(49) === false);
console.log(isBeatifulNumber(5679) === false);
console.log(isBeatifulNumber(40009) === false);
console.log(isBeatifulNumber(4114) === true);
console.log(isBeatifulNumber(55) === false);
console.log(isBeatifulNumber(4006) === true);
console.log(isBeatifulNumber(4009) === false);
console.log(isBeatifulNumber(4019) === false);
console.log(isBeatifulNumber('4019') === false);
console.log(isBeatifulNumber('401') === true);
console.log(isBeatifulNumber('abc') === false);
console.log(isBeatifulNumberHasThreeAndHasNotTwo('123') === false);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment