Created
January 27, 2022 23:07
-
-
Save rodrigogs/d800c59a09f79b4195e5115ac74c5523 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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