When inputting "12314" into the 'word' string below, everything functions correctly. However, if I enter characters like "abacd", the code encounters an error. Does anyone know why this might be happening? (1 in [1,2,3,1,4]) yields the correct result, but ('a' in [a,b,a,c,d] fails. I am still learning Javascript and would appreciate any insights.
var word = "abacd";
function duplicateEncode(word){
var repeat = [];
var result = [];
var letters = word.split('');
for (i=0; i < letters.length; i++){
if (letters[i] in repeat) {
result.push(")");
} else {
result.push("(");
}
repeat.push(letters[i]);
}
return result;
}