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

Не могу найти ошибку в коде. По преобразованию кода в http://jslint.com/ вопросов нет. #9

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
58 changes: 58 additions & 0 deletions dz1_NBronina/script_new.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
*Выполнение первого задания по преобразованию кода для совтировки задания. Программа работает не совсем корректно.
*Неправильно считываются данные их формы. Например, массив [1, 33, 65, 3, 5, 6] будет отсортирован не правильно,
*тогда как массив [1, 7, 8, 3, 5, 6] отсортируется верно.
*/
/*jslint browser: true, devel: true */
function sIncrease(i, ii) {
"use strict";
var returnval;
if (i > ii) {
returnval = 1;
} else if (i < ii) {
returnval = -1;
} else {
returnval = 0;
}
return returnval;
}
function sDecrease(i, ii) {
"use strict";
var returnval;
if (i > ii) {
returnval = -1;
} else if (i < ii) {
returnval = 1;
} else {
returnval = 0;
}
return returnval;
}
function validForm(x) {
"use strict";
var value, arr, count, i, j, max;
value = document.getElementById('mass').value;
value = value.replace(/,/g, '');
value = value.replace(/;/g, '');
value = value.replace(/,/g, '');
value = value.replace(/\;/g, '');
value = value.replace(/\[/g, '');
value = value.replace(/\]/g, '');
arr = value.split(" ");
count = arr.length - 1;
for (i = 0; i < count; i = i + 1) {
for (j = 0; j < count - i; j = j + 1) {
if (arr[j] > arr[j + 1]) {
max = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = max;
}
}
}
if (x === 'up') {
alert(arr);
}
if (x === 'down') {
alert(arr.sort(sDecrease));
}
}
35 changes: 35 additions & 0 deletions dz1_NBronina/sort.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="ru">
<head>
<title>сортировка массива</title>
<meta http-equiv="Content-Type" content="text/html />
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="script_new.js" type="text/javascript"></script>
<style type="text/css">
.l-level{
width: 500px;
margin: 0 auto;
padding-top: 200px;
}
.arr {width: 500px;}
.butt {position: relative; margin: 0 auto; width: 320px;}
.butt input {
display: block;
float: left;
margin: 10px;
}
</style>
</head>
<body>
<div class="l-level">
<form name="form">
<p>Введите массив для сортировки. Разделителями являются пробел, запятая, точка с запятой.</p>
<input class="arr" type="text" id="mass" />
<div class="butt">
<input id="up" type="button" onClick="validForm('up')" value="По возрастанию" /></span>
<input id="down" type="button" onClick="validForm('down')" value="По убыванию" /></span>
</div>
</form>
</div>
</body>
</html>