interface Movie {
title: string;
lengthMinutes: number;
}
var movies: Movie[] = [];
movies.push({
title: 'American History X',
lengthMinutes: 119,
production: 'USA'
});
movies.push({
title: 'Sherlock Holmes',
lengthMinutes: 128,
});
movies.push({
title: 'Scent of a Woman',
lengthMinutes: 157
});
function compareMovieLengths(x: Movie, y: Movie) {
if (x.lengthMinutes > y.lengthMinutes) {
return -1;
}
if (x.lengthMinutes < y.lengthMinutes) {
return 1;
}
return 0;
}
var moviesOrderedLength = movies.sort(compareMovieLengths);
var longestMovie = moviesOrderedLength[0];
console.log(longestMovie.title);