SHARE
TWEET

Untitled

a guest Sep 19th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 4
  2. const reverseArray = arr => {
  3.   let newArr = [];
  4.   for (let number of arr) {
  5.     newArr.unshift(number);
  6.   }
  7.   return newArr;
  8. };
  9.  
  10. console.log(reverseArray([1, 2, 1, 0]));
  11.  
  12. // 5
  13. const palindrome = input => {
  14.   const textInputArr = input
  15.     .toLowerCase()
  16.     .split('')
  17.     .filter(sign => sign.match(/[a-z]/i));
  18.   for (let i = 0, j = textInputArr.length - 1; i < j; i++, j--) {
  19.     if (textInputArr[i] !== textInputArr[j]) return console.log('NO');
  20.   }
  21.   console.log('YES');
  22. };
  23.  
  24. palindrome('4ABabA%');
  25.  
  26. // 6
  27. const permutation = (arr1, arr2) => {
  28.   const newArr1 = [...arr1];
  29.   if (arr1.length !== arr2.length) return console.log('NO');
  30.   for (let number of arr2) {
  31.     const index = newArr1.indexOf(number);
  32.     if (index > -1) newArr1.splice(index, 1);
  33.   }
  34.   if (newArr1.length > 0) return console.log('NO');
  35.   console.log('YES');
  36. };
  37.  
  38. permutation([1, 2, 3, 5, 4], [2, 4, 3, 1, 5]);
  39.  
  40. // 8
  41. const findingPrimes = (n, m) => {
  42.   const isPrime = n => {
  43.     if (n <= 3) return n > 1;
  44.     else if (n % 2 === 0 || n % 3 === 0) return false;
  45.     let i = 5;
  46.     while (i * i <= n) {
  47.       if (n % i === 0 || n % (i + 2) === 0) return false;
  48.       i += 6;
  49.     }
  50.     return true;
  51.   };
  52.  
  53.   let numberOfPrimes = 0;
  54.   for(let i = n; i <= m; i++) {
  55.     if (isPrime(i)) numberOfPrimes++;
  56.   }
  57.   return numberOfPrimes;
  58. };
  59.  
  60. console.log(findingPrimes(1, 10));
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top