Write functions that add or multiply all the elements in a given 1D or 2D array. Also write a general "fold" function for a 1D array.