Skip to content

Instantly share code, notes, and snippets.

@rodrigogs
Created January 27, 2022 23:07
Show Gist options
  • Save rodrigogs/d800c59a09f79b4195e5115ac74c5523 to your computer and use it in GitHub Desktop.
Save rodrigogs/d800c59a09f79b4195e5115ac74c5523 to your computer and use it in GitHub Desktop.
const findDuplicatedObjectKeyValues = (obj) => {
const propertyKeys = Object.keys(obj)
return propertyKeys.reduce((state, propertyKey, index) => {
const propertyValue = obj[propertyKey]
if (state.propertyValues.includes(propertyValue)) {
state.duplicatedValueKeys = [...state.duplicatedValueKeys, propertyKey]
}
state.propertyValues = [...state.propertyValues, propertyValue]
if (index === propertyKeys.length - 1) return state.duplicatedValueKeys
return state
}, { propertyValues: [], duplicatedValueKeys: [] })
}
module.exports = findDuplicatedObjectKeyValues
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment