Skip to content

Instantly share code, notes, and snippets.

@mdadils
Created July 16, 2023 17:03
Show Gist options
  • Save mdadils/233f5fd733846b8c2e38fd0ac04c73a0 to your computer and use it in GitHub Desktop.
Save mdadils/233f5fd733846b8c2e38fd0ac04c73a0 to your computer and use it in GitHub Desktop.
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