Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sort #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

sort #11

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Sort.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<HTML>
<BODY>
<script language="JavaScript" src="SortArray.js" type="text/javascript"></script>
</BODY>
</HTML>
46 changes: 46 additions & 0 deletions SortArray.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
var h = 0,
g = 0,
arr = [10];
//descending sort
function sort_array(i, j) {
"use strict";
if (i > j) {
return -1;
}
else {
if (i < j) {
return 1;
}
else {
return 0;
}
}
}
//printing array
function printing(g, arr) {
"use strict";
while (g < 10) {
document.write(arr[g], " ");
g = g + 1;
if (g > 10) {
return -1;
}
}
g = 0;
}
while (g < 10) {
arr[g] = g + 10 * Math.random();
g = g + 1;
if (g > 10) {
break;
}
}
document.write("Original array: ");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Лучше использовать console.log() вместо document.write()

document.write('<br><br>');
printing(h, arr);
document.write('<br><br>');
arr.sort(sort_array);
document.write("Descending sort: ");
document.write('<br><br>');
printing(h, arr);
alert("The sorting is finished");