daily pastebin goal
32%
SHARE
TWEET

Untitled

a guest Mar 21st, 2019 45 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function asteriscIt(n) {
  2.   // convert parameter to a string
  3.   // remove all commas and split into an array
  4.   let arr = n.toString().replace(/,/g, '').split('');
  5.   let result = [];
  6.   for ( let i = 0; i < arr.length; i++) {
  7.     if ( arr[i] % 2 === 0 && arr[i + 1] % 2 === 0) {
  8.       // if arr[i] is even && arr[i + 1] is even
  9.       result.push(arr[i] + '*')
  10.       // result = arr[i] *
  11.     } else {
  12.       result.push(arr[i])
  13.       //result = arr[i]
  14.     }
  15.   }
  16.   return result.join('')
  17.   // convert array back to string
  18. };
  19.  
  20. asteriscIt(5312708)
  21. 5312708 ==> "531270*8"
  22. asteriscIt([1, 2, 4, 8, 16])
  23. [1, 2, 4, 8, 16] ==> "12*4*816"
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
 
Top