Currently learning Javascript, and was doing an exercise with functions and objects. Why did this work:
decipher = (str, obj) => {
str = str.split("")
let keys = Object.keys(obj)
for(let i=0; i<str.length; i++) {
for(let j=0; j<keys.length; j++) {
if(str[i] === keys[j]) {
str[i] = obj[keys[j]]
}
}
}
return str.join("")
}
But this didn't?:
decipher = (str, obj) => {
str = str.split("")
let keys = Object.keys(obj)
for(let i of str) {
for(let j of keys) {
if(str[i] === keys[j]) {
str[i] = obj[keys[j]]
}
}
}
return str.join("")
}