Skip to content

Commit

Permalink
Array: Average (Warmup)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinsosborne committed Oct 9, 2017
1 parent 2a7fb39 commit 3c35664
Show file tree
Hide file tree
Showing 38 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Chapter 6 - Queues and Stacks/Reorder Absolute Queue.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

File renamed without changes.
21 changes: 21 additions & 0 deletions Chapter 7 - Arrays, Part II/Array: Average (Warmup).js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// (Warm-up) Always run through some quick algorithom problems before any coding interview, to get yourself warmed up. How about this one: return the average value of an array of unsorted numbers.

function average(arr){
if(arr.length > 0){
var sum = 0;
for(var i = 0; i < arr.length; i++){
sum = sum + arr[i];
}
var avg = sum / arr.length;
return avg;
}
else{
return "Array is Empty";
}
}

var arr = [1,2,3,4,5];
var output = average(arr);
console.log(output);
arr.push(6);
console.log(average(arr));

0 comments on commit 3c35664

Please sign in to comment.