SHARE
TWEET

isValidLinux

Bisix Jul 18th, 2019 (edited) 81 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function isValid(input) {
  2.  
  3.     let arrays = [
  4.         [
  5.             ['ubuntu'], // satu kata
  6.             ['linux', 'ubuntu'] // dua kata, urutan boleh bolak-balik
  7.         ],
  8.         [
  9.             ['kali'],
  10.             ['linux', 'kali']
  11.         ]
  12.     ]
  13.  
  14.     let arrInput = input.split(' ').filter(v => v)    
  15.     if ((new Set(arrInput)).size !== arrInput.length) {
  16.         // found duplicate items -> invalid
  17.         return false
  18.     }
  19.  
  20.     for (const arr_ of arrays) {
  21.         for (const arr of arr_) {
  22.             if (arr.length !== arrInput.length) continue
  23.             if (arrInput.every(v => arr.includes(v))) {
  24.                 // valid
  25.                 return true
  26.             }
  27.         }
  28.     }
  29.  
  30.     return false
  31. }
  32.  
  33. console.info(isValid("ubuntu linux"))
  34. console.info(isValid("ubuntu"))
  35. console.info(isValid("linux"))
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