Last active
August 29, 2015 13:59
-
-
Save rvbsanjose/10620952 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Using the JavaScript language, have the function MeanMode(arr) take the array of numbers stored in arr and return 1 if | |
// the mode equals the mean, 0 if they don't equal each other (ie. [5, 3, 3, 3, 1] should return 1 because the mode (3) equals | |
// the mean (3)). The array will not be empty, will only contain positive integers, and will not contain more than one mode. | |
// Input = 1, 2, 3Output = 0 | |
// Input = 4, 4, 4, 6, 2Output = 1 | |
function MeanMode( arr ) { | |
var sum = 0; | |
arr.forEach( function ( el, idx, ary ) { | |
sum += el; | |
}); | |
var mean = parseInt( sum / arr.length ); | |
var mode = arr.filter( function ( el ) { | |
return el == mean; | |
}); | |
return mode.length > 1 ? 1 : 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment