What does chars[word]
store in both the condition !chars[word]
and chars[word]>max
and how does it compare according to index
function repeat(str) {
let chars = {}
let arr = str.split('').reverse().join('')
for (let word of arr) {
if (!chars[word]) {
chars[word] = 1
} else {
chars[word]++
}
console.log(chars)
let max = 0
let repeatedword = ''
for (let word of arr) {
if (chars[word] > max) {
max = chars[word]
repeatedword = word
}
}
console.log(repeatedword)
}
} function repeat ("hello how are you hello world I'm hello")