Skip to content

Instantly share code, notes, and snippets.

@LESTADru
Created February 4, 2014 18:59
Show Gist options
  • Save LESTADru/8810027 to your computer and use it in GitHub Desktop.
Save LESTADru/8810027 to your computer and use it in GitHub Desktop.
код, который отсортирует массив объектов people по полю age.
<!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