jaimex8
1/26/2016 - 1:15 AM

Go through numbers in array, stop at 0 and add up previous numbers. Reduce function.

Go through numbers in array, stop at 0 and add up previous numbers. Reduce function.

function houseNumbersSum(inputArray) {
	var arr = [];
	for (var i = 0; i < inputArray.length; i++) {
		if(inputArray[i] == 0){
			break;
		}
		arr.push(inputArray[i]);
	};
	if (arr.length < 1){
		return 0;
	}
	return arr.reduce(function(prev,cur){
		return prev + cur;
	})

}