Skip to content

Instantly share code, notes, and snippets.

@mcsee
Created April 27, 2025 15:50
Show Gist options
  • Save mcsee/2928b4ea3bd26eb6e8cdd079440e0437 to your computer and use it in GitHub Desktop.
Save mcsee/2928b4ea3bd26eb6e8cdd079440e0437 to your computer and use it in GitHub Desktop.
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
function isNotNull(x) {
return x !== null && x !== undefined
// Another code smell here
}
function mapToValueAndMeta(y) {
const meta = y.meta ? y.meta : { default: true }
return { val: y.value, meta }
}
function reduceToProcessedList(acc, { val, meta }) {
if (meta.default) {
return acc
}
return [...acc, { processed: val * 2, origin: meta }]
}
function isProcessedInRange({ processed }) {
return processed > 10 && processed < 50
}
// This is more declarative but far from
// Domian business and too generic
const filtered = arr.filter(isNotNull)
const mapped = filtered.map(mapToValueAndMeta)
const processedList = mapped.reduce(reduceToProcessedList, [])
const result = processedList.some(isProcessedInRange)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment