Created
February 4, 2014 18:59
-
-
Save LESTADru/8810027 to your computer and use it in GitHub Desktop.
код, который отсортирует массив объектов people по полю age.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="UTF-8"> | |
<title>код, который отсортирует массив объектов people по полю age..</title> | |
</head> | |
<body> | |
<script> | |
'use strict' | |
var vasya = { name: "Вася", age: 23 }; | |
var masha = { name: "Маша", age: 18 }; | |
var vovochka = { name: "Вовочка", age: 6 }; | |
var people = [ vasya , masha , vovochka ]; | |
function peopleSort(a, b){ | |
return a.age - b.age; | |
} | |
people.sort(peopleSort); | |
alert(people[0].age); | |
alert(people[1].age); | |
alert(people[2].age); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment