Created
April 27, 2025 15:50
-
-
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
This file contains hidden or 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
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