-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
34 lines (30 loc) · 921 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
/**
* --- Day 4: High-Entropy Passphrases - Part I ---
*
* This function checks whether the string passed as a parameter is a valid
* passphrase or not. A valid passphrase must include over one word separated
* by spaces, with all of these words being different from one another.
*
* @author Sara Hernández <[email protected]>
*
* @param {string} input - A string representing the passphrase to check.
* @return {boolean}
*/
const isValidPassphrase = function (input = "") {
const words = input.split(" ");
if (words.length < 2) {
console.log(`Input must contain more than one word.`);
return false;
}
const wordIndex = {};
for (const word of words) {
if (wordIndex.hasOwnProperty(word)) {
console.log(`Input contains duplicate word '${word}'`);
return false;
} else {
wordIndex[word] = null;
}
}
return true;
};
module.exports = isValidPassphrase;