Created
February 12, 2025 17:52
-
-
Save jamescurran/0d8032bbc8e97488b66667bfa8d6903b to your computer and use it in GitHub Desktop.
Daily Challenge: JS-95 Calculate the Product of Non-Zero Elements (in C#)
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
| /* | |
| The Challenge | |
| Difficulty: Easy | |
| Topic: Array Manipulation | |
| Description | |
| Given an array of integers, write a function to calculate the product | |
| of all non-zero elements in the array. | |
| If no non-zero element exists, return 1. | |
| */ | |
| int[] array = { 1, 2, 0, 4, 5, 6, 0 }; | |
| array | |
| .Where(n => n!=0) | |
| .Aggregate (1, (product, factor) => product * factor ) | |
| .Dump() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment