arr = [1, 2, 3, 3, 1, 2, 3, 4, 1, 2, 3, 4];
let arr = [1, 2, 3, 3, 1, 2, 3, 4, 1, 2, 3, 4]
const f = a => {
const b = {},
c = []
a.forEach((e, i) => e % 2 !== 0 ? b[e] ? b[e].push(i) : b[e] = [i] : null)
for (let g in b) {
b[g].length > 1 ? c.push(b[g].slice(0, -1)) : c.push(b[g])
}
return c.flat().sort((x, y) => x - y)
}
console.log(f(arr)) // [0, 2, 3, 4, 6]