Skip to content

Instantly share code, notes, and snippets.

@ldco2016
Created October 24, 2016 02:57
Show Gist options
  • Select an option

  • Save ldco2016/5b2151f2d2859288983a99aad3719c1a to your computer and use it in GitHub Desktop.

Select an option

Save ldco2016/5b2151f2d2859288983a99aad3719c1a to your computer and use it in GitHub Desktop.
Code Test
<!DOCTYPE html>
<html>
<body>
<script>
// person constructor
function Person(name, rank) {
this.name = name;
this.rank = rank;
}
// create the object with the array
var myObject = {
myArray: new Array()
};
// populate the array
myObject.myArray.push(new Person('Norman', 9));
myObject.myArray.push(new Person('Naomi', 3));
myObject.myArray.push(new Person('Albert', 10));
myObject.myArray.push(new Person('Vanessa', 1));
myObject.myArray.push(new Person('Chanel', 3));
myObject.myArray.push(new Person('Rick', 10));
myObject.myArray.push(new Person('Diamond', 1));
myObject.myArray.push(new Person('Sinnamon', 2));
myObject.myArray.push(new Person('Angel', 1));
myObject.myArray.push(new Person('Marie', 8));
// sort the Person objects according to their ranks
myObject.myArray.sort(function(a, b) {
return b.rank - a.rank;
});
var avg = Person.length;
document.write( " The average is: " + avg );
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment