Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>JS Bin</title>
</head>
<body>
  
</body>
</html>
 
function arraySum(i) {
    var sum=0;
    for(var a=0;a<i.length;a++){
        if(typeof i[a]=="number"){
            sum+=i[a];
        }else if(i[a] instanceof Array){
            sum+=arraySum(i[a]);
        }
    }
    return sum;
}
console.log(arraySum([1,2,[3,4],[5]]));
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
Tibospro
0viewers