Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

calculate sum in empty array javascript

function sum(numbers){
  var x = numbers.reduce(function(prev,curr){
    return curr + prev;
  },0);
  return x;
}

alert(sum([1,2,3]));
alert(sum([]));
Comment

PREVIOUS NEXT
Code Example
Javascript :: res.write image url 
Javascript :: competitive programming in javascript 
Javascript :: beanstalk nodejs default port 
Javascript :: JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array. 
Javascript :: jquery-3.5.0.min.js 
Javascript :: vuejs input call the value 
Javascript :: export socket io connection in react 
Javascript :: node.js express export routes 
Javascript :: arguments in javascript 
Javascript :: jquery selector input name regex 
Javascript :: You might have more than one copy of React in the same app. 
Javascript :: vscode angular: running ngcc 
Javascript :: js .length 
Javascript :: remove all white spaces and different characters globally 
Javascript :: file-loader support json file 
Javascript :: choco node 17 
Javascript :: how to check url with port is valid or not regex javascript 
Javascript :: reactnaviataion change title 
Javascript :: alpinejs examples stackoverflow 
Javascript :: yup.array not working 
Javascript :: promise .then javascript 
Javascript :: how to find keycode in javascript 
Javascript :: get image from s3 bucket angular 
Javascript :: javascript decrement 
Javascript :: javascript getter 
Javascript :: using javascript array create bootstrap card 
Javascript :: check if all array elements are equal 
Javascript :: moment get difference between business dates 
Javascript :: how to update specific key of an object in reducer 
Javascript :: jquery select element inside element 
ADD CONTENT
Topic
Content
Source link
Name
2+2 =