Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Average Of Numbers

const average = (...args) => args.reduce((a, b) => a + b) / args.length;

average(1, 2, 3, 4);
// Result: 2.5
Comment

find average

const arr = [2, 4, 5, 6];

// Find average function
function fAve(totalVal, arrVal, index, array) {
	const val = totalVal + arrVal;
    
    if (index === array.lengh -1) {
    	return val / array.length;
    }
    
    return val;
}

// Pass function into reduce method
const average = arr.reduce(fAve);

console.log(average);


//node (js file name).
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript map 
Javascript :: javascript ES6 Default Parameter Values 
Javascript :: next js react image upload 
Javascript :: backtick string javascript 
Javascript :: node sudo nvm 
Javascript :: javascript parsestring 
Javascript :: react-loader-spinner 
Javascript :: json array in hidden field not coming 
Javascript :: javascript .firstordefault 
Javascript :: onclick send to email javascript 
Javascript :: update angular project 
Javascript :: bcrypt 
Javascript :: js change h 
Javascript :: js timezone location 
Javascript :: javascript mysql query 
Javascript :: loop node list 
Javascript :: volume slider javascript 
Javascript :: acheck angular version 
Javascript :: Key Type 
Javascript :: button change slider value js 
Javascript :: hashtable js 
Javascript :: two digits number javascript 
Javascript :: javascript remove scientific notation 
Javascript :: how to install nuxtjs with tailwind css 
Javascript :: javascript static variable in class 
Javascript :: how to create a website with javascript 
Javascript :: Open temporary webpage js 
Javascript :: javascript some 
Javascript :: find duplicates in array 
Javascript :: java script strict tag 
ADD CONTENT
Topic
Content
Source link
Name
8+4 =