-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduplicateEncoder.js
More file actions
31 lines (25 loc) · 849 Bytes
/
duplicateEncoder.js
File metadata and controls
31 lines (25 loc) · 849 Bytes
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
function duplicateEncode(word){
word = word.toLowerCase()
let result = ''
for (let letter of word) {
if (appearsMoreThanOnce(word,letter)) {
result += ')'
} else {
result += '('
}
}
return result
}
let appearsMoreThanOnce = (word, letter) => {
if ((word.split(letter).length - 1) > 1) {
return true
} else return false
}
//Parameters: A string, I believe it will only be one word, but I know that spaces are allowed so that doesn't
//really matter
//Return value: a new string, consisting of the parentheses characters, '(' and ')', ignoring case
//Example: 'Hamilton Morris' will return '(())(()(()())()'
//Psuedocode: iterate through word
//for each letter, if (apearsMoreThanOnce(word,letter)) {
// result += ')'
// else result +='('