I'm feeling a bit puzzled right now. Allow me to provide a straightforward example to showcase the issue I'm encountering.
I have certain expectations from the code: when current = 3, it should return 'before'; when current = 4, it should return 'key-two'; when current = 5, it should return 'between'; when current = 7, it should return 'key-two'; and when current = 8, it should return 'after'.
Unfortunately, the code isn't producing the expected results. When I set current to 7, it returns 'key-two'; when I set it to 8 or higher, it returns 'after'; and any other number results in 'between'.
let items = []
items['key-one'] = 4
items['key-two'] = 7
let current = 3
let results = ''
for(let key in items) {
let keyOne = ''
let keyTwo = ''
if (key === 'key-one') {
keyOne = items[key]
}
if (key === 'key-two') {
keyTwo = items[key]
}
if (current < keyOne) {
results = 'before'
}
else if (current === items[key]) {
results = key
}
else if (current > keyOne && current < keyTwo) {
results = 'between'
}
else if (current > keyTwo) {
results = 'after'
}
}
document.write(results)