Skip to content

Instantly share code, notes, and snippets.

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

  • Save jamescurran/426ad0460bcdca864c693d2cd416460a to your computer and use it in GitHub Desktop.

Select an option

Save jamescurran/426ad0460bcdca864c693d2cd416460a to your computer and use it in GitHub Desktop.
Daily Challenge: JS-96 Sum Digit Sequence
/* The Challenge
Difficulty: Easy
Topic: Array manipulation
Description
Given an array of numbers, calculate the sum of digits for each number
and return a new array containing these sums in the same order.
*/
void Main()
{
int[] array = { 123, 456, 789};
array.Select(x => GetDigits(x).Sum()).ToArray().Dump();
}
IEnumerable<int> GetDigits(int num)
{
while(num > 0)
{
yield return num % 10;
num = num / 10;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment