JSFiddle - React, Tailwind, and code Playground
HTML
<table>
<tr><td>.apply()</td><td id="apply-result">...</td></tr>
<tr><td>literal</td><td id="eval-result">...</td></tr>
</table>
<script type="text/javascript">
$(document).ready(function () {
$('.mes').mask('00');
$('.ano').mask('0000');
$('.chave').mask('000000000');
$('.For').mask('0000');
$('.Hora').mask('00');
$('.Minuto').mask('00');
$('.Nivel').mask('9999,99');
$('.Vazao').mask('9999,99');
$("#txtFor").val("89");
$("#txtMes").change(function () {
if (this.value > 12) {
$("#txtChaveEstacaoQuantitativa").focus();
$("#txtMes").focus();
$("#txtMes").val("");
$("#msgErroMes").css("display", "inline").fadeOut(90000);
}
else {
$("#txtAno").focus();
}
});
$("#txtAno").change(function () {
if (this.value <= 0) {
$("#txtAno").focus();
$("#txtAno").val("");
}
});
$("#txtAno").focusout(function () {
var dataatual = new Date();
var anoatual = dataatual.getFullYear();
if (this.value > anoatual) {
$("#txtAno").focus();
$('#lblSalvo').text("O ANO deve ser menor ou igual ao ANO CORRENTE.");
}
else if ($(this).val().length != 4) {
$("#txtAno").focus();
$('#lblSalvo').text("O ANO deve deve conter 4 DIGITOS.");
}
else {
$('#lblSalvo').text("");
}
});
$("#txtResp").focusout(function () {
if ($(this).val().length > 200) {
$("#txtResp").focus();
...
CSS
table {
border-collapse: collapse;
font-family: sans-serif;
font-size: 16px;
text-align: center;
}
td {
border: 1px solid black;
padding: 10px;
}
JavaScript
function repeat(val, n) {
var array = [];
while(--n >= 0) {
array.push(val);
}
return array;
}
function throwsException(f) {
try {
f();
return false;
} catch(e) {
return true;
}
}
function canApply(n) {
var array = repeat(0, n);
return !throwsException(function() {
(function() {}).apply(null, array);
});
}
function canEval(n) {
var code = '(function() {})(' + repeat('0', n).join(',') + ')';
return !throwsException(function() {
eval(code);
});
}
function find(f) {
for(var high = 1; high < 1e7 && f(high); high *= 2);
var mid;
for(var low = high-- / 2; low < high; ) {
mid = (low + high + 1) / 2;
if(f(mid)) {
low = mid;
} else {
high = mid - 1;
}
}
return mid;
}
setTimeout(function() {
document.getElementById('apply-result').innerHTML = find(canApply).toString();
}, 0);
setTimeout(function() {
document.getElementById('eval-result').innerHTML = find(canEval).toString();
}, 0);