Created
September 19, 2022 18:06
-
-
Save waterrmalann/5948c67b2d82e3877220b15b0a9d5de2 to your computer and use it in GitHub Desktop.
JavaScript port of the python script that can generate memorable random numbers between two integer ranges.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Memorable Integer Generator: JavaScript Port | |
*/ | |
String.prototype.reverse = function() { | |
return this.valueOf().split("").reverse().join(""); | |
} | |
class MIG { | |
constructor(minimum, maximum) { | |
this.minimum = minimum; | |
this.maximum = maximum; | |
this.list = []; | |
for (let _num = minimum; _num < maximum; _num++) { | |
let _numAsStr = _num.toString(); | |
if (_numAsStr.reverse() === _numAsStr) { | |
// palindrome | |
this.list.push(_num); | |
} else if (_num % 100 == 0) { | |
// divisible by 100 | |
this.list.push(_num); | |
} else if (new Set(_numAsStr).size <= 2) { | |
// common | |
this.list.push(_num); | |
} else if ("0123456789".indexOf(_numAsStr) != -1) { | |
// increasing | |
this.list.push(_num); | |
} else if ("9876543210".indexOf(_numAsStr) != -1) { | |
// decreasing | |
this.list.push(_num); | |
} | |
} | |
// To-Do: is repeating | |
} | |
generate() { | |
return this.list[Math.floor(Math.random() * this.list.length)]; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment