Last active
          December 18, 2024 11:28 
        
      - 
      
- 
        Save sandrabosk/17319bb427dc4e457595d6670a455f57 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
    
  
  
    
  | // ************************************************************************************ | |
| // https://www.codewars.com/kata/5539fecef69c483c5a000015/javascript | |
| // Find all Backwards Read Primes between two positive given numbers (both inclusive), | |
| // the second one always being greater than or equal to the first one. | |
| //The resulting array or the resulting string will be ordered following the natural order | |
| // of the prime numbers. | |
| // Example | |
| // backwardsPrime(2, 100) => [13, 17, 31, 37, 71, 73, 79, 97] | |
| // backwardsPrime(9900, 10000) => [9923, 9931, 9941, 9967] | |
| // backwardsPrime(501, 599) => [] | |
| // ************************************************************************************ | |
| function backwardsPrime(start, stop) { | |
| // your code here | |
| let result = []; | |
| for (let i = start; i <= stop; i++) { | |
| // check if the number is prime | |
| // if it is prime check if the backwards no is prime too | |
| if (isPrime(i) && isReversePrime(i)) { | |
| result.push(i); | |
| } | |
| } | |
| return result; | |
| } | |
| function isPrime(num) { | |
| for (let i = 2; i <= Math.sqrt(num); i++) { | |
| if (num % i === 0) { | |
| return false; | |
| } | |
| } | |
| return true; | |
| } | |
| function isReversePrime(num) { | |
| let reverseNum = +num.toString().split("").reverse().join(""); | |
| if (num !== reverseNum) { | |
| return isPrime(reverseNum); | |
| } | |
| return false; | |
| } | 
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
            
Greate job!!!