Показать сообщение отдельно
  #5 (permalink)  
Старый 29.07.2016, 11:06
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,070

Радиойод,
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">

</head>

<body>
<input type="text" id="A"><br>
<input type="text" id="B"><br>
<input type="text" id="C"><br>
<input type="text" id="D"><br>
<input type="text" id="E"><br>
<input type="text" id="F"><br>
<input type="text" id="G"><br>
<input type="text" id="H"><br>
<input type="text" id="I"><br>
<input type="text" id="J"><br>
<script>
function foo(data)
{
  var str = "ABCDEFGHIJ";
  data.reduce(function(a, b, i) {
  if(a > b || i == 1 && a == b) document.getElementById(str[i]).value = a + b;
  return b
},data.slice(-1)[0])
}
foo([10,10,9,8,7,6,5,4,3,100])
function test(a,b,c,d,e,f,g,h,i,j)
{
   if (b==a)
document.getElementById("B").value = a + b;
 if (b>c)
document.getElementById("C").value = c + b;
if (c>d)
document.getElementById("D").value = c + d;
if (d>e)
document.getElementById("E").value = d + e;
  if (e>f)
document.getElementById("F").value = e + f;
  if (f>g)
document.getElementById("G").value = f + g;
    if (g>h)
document.getElementById("H").value = g + h;
    if (h>i)
document.getElementById("I").value = h + i;
    if (i>j)
document.getElementById("J").value = i + j;  alert([i,j])
    if (j > a)
document.getElementById("A").value = j + a;
}
//test(10,10,9,8,7,6,5,4,3,100)
</script>

</body>
</html>


для проверки
<!DOCTYPE html>

<html>
<head>
  <title>Untitled</title>
  <meta charset="utf-8">

</head>

<body>
<input type="text" id="A"><br>
<input type="text" id="B"><br>
<input type="text" id="C"><br>
<input type="text" id="D"><br>
<input type="text" id="E"><br>
<input type="text" id="F"><br>
<input type="text" id="G"><br>
<input type="text" id="H"><br>
<input type="text" id="I"><br>
<input type="text" id="J"><br>
<script>
function foo(data)
{
  var str = "ABCDEFGHIJ";
  data.reduce(function(a, b, i) {
  if(a > b || i == 1 && a == b) document.getElementById(str[i]).value = a + b;
  return b
},data.slice(-1)[0])
}
//foo([10,10,9,8,7,6,5,4,3,100])
function test(a,b,c,d,e,f,g,h,i,j)
{
   if (b==a)
document.getElementById("B").value = a + b;
 if (b>c)
document.getElementById("C").value = c + b;
if (c>d)
document.getElementById("D").value = c + d;
if (d>e)
document.getElementById("E").value = d + e;
  if (e>f)
document.getElementById("F").value = e + f;
  if (f>g)
document.getElementById("G").value = f + g;
    if (g>h)
document.getElementById("H").value = g + h;
    if (h>i)
document.getElementById("I").value = h + i;
    if (i>j)
document.getElementById("J").value = i + j;  
    if (j > a)
document.getElementById("A").value = j + a;
}
test(10,10,9,8,7,6,5,4,3,100)
</script>

</body>
</html>
Ответить с цитированием