Created
July 16, 2023 17:03
-
-
Save mdadils/233f5fd733846b8c2e38fd0ac04c73a0 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
var isPollutedObject = (data)=>{ | |
// simple string wala use case | |
if (typeof data === 'string') { | |
if (data.includes('BAD')) { | |
return true; | |
} else { | |
return false; | |
} | |
} | |
// Object wala use case | |
if (typeof data === 'object') { | |
return !!Object.keys(data).find(key=>isPollutedObject(data[key])); | |
} | |
return false; | |
} | |
console.log(isPollutedObject({})); | |
console.log(isPollutedObject({ | |
a: true, | |
b: { | |
c: 'good', | |
d: { | |
e: "yes" | |
} | |
} | |
})); | |
console.log(isPollutedObject({ | |
a: true, | |
b: { | |
c: 'goodBAD', | |
d: { | |
e: "yes" | |
} | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment