Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function isValid(input) {
- let arrays = [
- [
- ['ubuntu'], // satu kata
- ['linux', 'ubuntu'] // dua kata, urutan boleh bolak-balik
- ],
- [
- ['kali'],
- ['linux', 'kali']
- ]
- ]
- let arrInput = input.split(' ').filter(v => v)
- if ((new Set(arrInput)).size !== arrInput.length) {
- // found duplicate items -> invalid
- return false
- }
- for (const arr_ of arrays) {
- for (const arr of arr_) {
- if (arr.length !== arrInput.length) continue
- if (arrInput.every(v => arr.includes(v))) {
- // valid
- return true
- }
- }
- }
- return false
- }
- console.info(isValid("ubuntu linux"))
- console.info(isValid("ubuntu"))
- console.info(isValid("linux"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement