BETEPAH,
разделить на .5 всёравно что умножить 2 я в этом плане |
рони,
так я же не спорю, говорю же без сарказма. На полноценный вариант это с трудом катит, так как разделить на .5 и умножить на 2 это все равно, что сделать бинарный левый сдвиг на 1 :) Ну и двойка вынесена за скобки. |
Всем спасибо взял вариант nerv_, как более простой и короткий.
|
Цитата:
<script> x=false; y=true; document.write([ x && 1 || -1 , y && 1 || -1 ]) </script> |
MallSerg,
:victory: зачёт |
MallSerg, тогда уж так:
<script> x=false; y=true; document.write([ +x || -1 , +y || -1 ]) </script> Хотя фигня всё это, на деле я бы пользовался вариантом номер два, ибо просто и наглядно. |
Aetae,
:victory: |
Любопытные результаты в разных браузерах )
<script>
var ret=0 , t1, t2 , x=false;
t1 = new Date();
ret = 0;
for (i=0; i < 10000000 ; i++){ret += (x << 1) - 1 } ;
t2 = new Date();
document.write(t1-t2); document.write("<br>");
document.write(ret); document.write("<br>");
//------------------------
t1 = new Date();
ret = 0;
for (i=0; i < 10000000 ; i++){ret += x ? 1 : -1 } ;
t2 = new Date();
document.write(t1-t2); document.write("<br>");
document.write(ret); document.write("<br>");
//------------------------
t1 = new Date();
ret = 0;
for (i=0; i < 10000000 ; i++){ret += x - !x ;} ;
t2 = new Date();
document.write(t1-t2); document.write("<br>");
document.write(ret); document.write("<br>");
//------------------------
t1 = new Date();
ret = 0;
for (i=0; i < 10000000 ; i++){ret += (x - .5) * 2 ;} ;
t2 = new Date();
document.write(t1-t2); document.write("<br>");
document.write(ret); document.write("<br>");
//------------------------
t1 = new Date();
ret = 0;
for (i=0; i < 10000000 ; i++){ret += +x || -1 ;} ;
t2 = new Date();
document.write(t1-t2); document.write("<br>");
document.write(ret); document.write("<br>");
//------------------------
</script>
|
| Часовой пояс GMT +3, время: 00:54. |