Given an array of strings, add all the numeric values within the array and print the sum to stdout. If there are no numeric values, print 0.
Note: The sum will not exceed 7,000,000.
my_array = ["First", "2", "third", "4"]
The array_sum function should return 6 because 2 + 4 = 6.
The input contains the newline-separated elements of the given array.
Sample Input For Custom Testing
Abc 20 Efg231 10 cDe
Sample Output 30
The numerical elements are 20 and 10 that sum to 30.
Sample Input For Custom Testing
SingleWord
Sample Output 0
No numeric elements are present in the array.
Note: In platform you have to code in Bash
!/usr/bin/env bash
// Input array is read and stored into my_array variable. // You can view the code by pressing > button above.
function array_sum() { typeset -a data=("$@") # Write your code here }
array_sum "${my_array[@]}"
Hard