[CHALLENGE] avg (average) function | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 15

[CHALLENGE] avg (average) function

Another simple challenge. Create avg function. Given input for example: arr = [1,2,3,4,5] Output: result = 3 (because it's average of whole arr list)

16th Feb 2018, 8:06 AM
r8w9
r8w9 - avatar
12 Answers
16th Feb 2018, 10:11 AM
LukArToDo
LukArToDo - avatar
+ 10
function avg(list) { var sum = pop = 0 while (list.length) { sum += list.pop()*1 pop++ } return sum/pop }//avg console.log(avg([1,2,3,4,5]))
16th Feb 2018, 9:43 AM
Valen.H. ~
Valen.H. ~ - avatar
+ 9
I didnt read it properly the first time 😉 https://code.sololearn.com/cH48c92x9O13/?ref=app
16th Feb 2018, 12:12 PM
D_Stark
D_Stark - avatar
+ 6
r8w9 I can submit your challenges in Lesson Factory like Assignment and get the bagde Creator
8th Jul 2018, 10:39 AM
Biel Blue
Biel Blue - avatar
16th Feb 2018, 1:17 PM
Obbu
Obbu - avatar
16th Feb 2018, 9:34 PM
Pedro Demingos
Pedro Demingos - avatar
17th Feb 2018, 10:04 AM
luʁi
+ 2
Own implementation without "list.average()" https://code.sololearn.com/cb9rjtQ9ca4I/
16th Feb 2018, 10:56 AM
ISkylake
ISkylake - avatar
+ 1
https://code.sololearn.com/c28ooBCtEmAm/?ref=app
16th Feb 2018, 9:53 AM
ISkylake
ISkylake - avatar