function duplicates(arr) {
  const res = []
  const countObj = arr.reduce((pre, next) => {
     if (pre[next]) {
       pre[next]++
     } else {
       pre[next] = 1
     }
    return pre
  }, {}) 

  for (let key in countObj) {
    if (countObj[key] > 1) {
      res.push(key)
    }
  }
   return res
}