How do I add the numbers of an array

I have a list consisting of numbers and - unfortunately - a suctraction sign.
var saleItems=sales[i].toString();
trace(saleItems) results in the below
//
1
-
-
3
-
-
1
-
1
-
-
-
3
-
-
-
-
-
1
2
2
-
1
1
-
9

Open in new window


How do I add the numbers and how do I remove the subtraction-signs.
petersegoAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

dgofmanCommented:
var validChars:String = "0123456789";
var saleItems:Array = ["1", "2", "+", "-", "3", "4"];
for(var i:Number = saleItems.length - 1; i >= 0; i--){
	if(validChars.indexOf(saleItems[i]) == -1)
		saleItems.splice(i, 1);
}
trace(saleItems) 

Open in new window

petersegoAuthor Commented:
Thanks, that seems to work, but how do I get a sum of the numbers. In your example the sum 10.
dgofmanCommented:
You can use string.length and charAt function for substring and compare each symbol in your area item. I cannot code for now but is
Loop inside loop. Try to write code if not I will submit my version an in hour

dgofmanCommented:
var validChars:String = "0123456789";
var saleItems:Array = ["1", "2", "+", "-", "3", "4", "1c", "10"];
for(var i:Number = saleItems.length - 1; i >= 0; i--){
	var item:String = saleItems[i];
	for(var c:Number = 0; c < item.length; c++){
		if(validChars.indexOf(item.charAt(c)) == -1){
			saleItems.splice(i, 1);
			break;
		}
	}
}
trace(saleItems)  

//Another solution working for ALL number, but you cannot controll for example skip number 5 or 6
var saleItems:Array = ["1", "2", "+", "-", "3", "4", "1c", "10"];
for(var i:Number = saleItems.length - 1; i >= 0; i--){
	if(isNaN(new Number(saleItems[i])))
		saleItems.splice(i, 1);
}

trace(saleItems)  

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
petersegoAuthor Commented:
Thanks, they works fine, but I did a try myself and ended up with this solution.

var total:Array=[];
var sum:Number=0;
var salesItems:Array=["1", "2", "+", "-", "3", "4", "1c", "10"];
for each(var o:Number in salesItems){
    if(!o){
          o=0;
    }
    total.push(o);
}
for (var i:Number = 0; i < total.length; i++){
    sum+=total[i];			
}
trace(sum);      // 20

Open in new window


It seems to work.

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.