flatMap With Empty Results
flatMap With Empty Results
flatMap lets a callback return an empty array when a source item should contribute nothing. That is different from returning null or an empty string, which would still add an item to the final result.
Permission systems often need this one-to-many shape. A group can be disabled, enabled with no permissions, or enabled with several permissions. The final list should contain permission keys only, in group order, without nested arrays or placeholder values.
Your task: Complete enabledPermissionKeys so it returns a flat list of permission keys from enabled groups. Disabled groups and groups with no permissions should not add anything to the result.
Free with a JS Exercises account
Sign in to start coding, run your solution, and keep your progress saved for later. No payment needed.
By continuing, you agree to our Terms and Privacy Policy. We'll send occasional product updates and news. You can unsubscribe anytime.
flatMap With Empty Results
flatMap lets a callback return an empty array when a source item should contribute nothing. That is different from returning null or an empty string, which would still add an item to the final result.
Permission systems often need this one-to-many shape. A group can be disabled, enabled with no permissions, or enabled with several permissions. The final list should contain permission keys only, in group order, without nested arrays or placeholder values.
Your task: Complete enabledPermissionKeys so it returns a flat list of permission keys from enabled groups. Disabled groups and groups with no permissions should not add anything to the result.