DOCTYPE html -- To change this license header choose License Headers i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->
<html>
<head>
<title>Hello gnomeSort</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width">
<script>
function read(file)
{
if (window.File && window.FileReader && window.FileList && window.Blob)
{
var fr = new FileReader();
fr.readAsText(file.files[0]);
fr.onload = function (e)
{
document.getElementById('dates').innerHTML = getSortedList(e.target.result);
};
}
}
function getSortedList(data)
{
var dates = data.split('\r\n');
for (var i = 0; i < dates.length; i++)
{
dates[i] = dates[i].split(' ');
dates[i][1] = dates[i][1] + ' ' + dates[i][2];
dates[i][0] = new Date(Date.parse(dates[i][0]));
}
dates = sortDates(dates);
var text = '<ul>';
for (var i in dates)
{
text += '<li>' + dates[i][0].toString() + ' | ' + dates[i][1].toString() + '</li>';
}
text += '</ul>'
return text;
}
function sortDates(dates)
{
for (var i = 0; i < dates.length; i++)
{
for (var j = 0; j < dates.length - 1; j++)
{
if (dates[j][0] > dates[j + 1][0])
{
var temp = dates[j + 1];
dates[j + 1] = dates[j];
dates[j] = temp;
}
}
}
return dates;
}
</script>
</head>
<body>
<input type='file' onChange='read(this)' />
<div id='dates'>
</div>
</body>
</html>