Skip to content

Instantly share code, notes, and snippets.

@jamescurran
Created February 12, 2025 17:52
Show Gist options
  • Select an option

  • Save jamescurran/0d8032bbc8e97488b66667bfa8d6903b to your computer and use it in GitHub Desktop.

Select an option

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#)
/*
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