Last active
January 28, 2020 05:40
-
-
Save AhmedHelalAhmed/2384e9ee2a207b2e4cf1ffa23e90b0d5 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| // names here like ahmed belong to the owner of the problem | |
| let prtext = "Egy"; | |
| let ahmed = function() { | |
| let a = Math.floor(Math.random() * prtext.length); | |
| let b = ""; | |
| let whichRange = getRandomIntBetweenTwoValues(1, 2); | |
| // to handle the critical values | |
| if(a==0) | |
| { | |
| whichRange=2; | |
| } | |
| if(b== prtext.length) | |
| { | |
| whichRange=1; | |
| } | |
| // to handle the critical values | |
| let min1 = 0; | |
| let max1 = a - 1; | |
| let min2 = a + 1; | |
| let max2 = prtext.length; | |
| //====================> range 1 | |
| if (whichRange == 1) { | |
| b = getRandomIntBetweenTwoValues(min1, max1); | |
| } | |
| //====================> range 2 | |
| if (whichRange == 2) { | |
| b = getRandomIntBetweenTwoValues(min2, max2); | |
| } | |
| if (a !== b) { | |
| console.log(a, b); | |
| } | |
| console.log(a, b); | |
| }; | |
| function getRandomIntBetweenTwoValues(min, max) { | |
| return Math.floor(Math.random() * (max - min + 1)) + min; | |
| } | |
| ahmed(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment