by cpglkg
<script>
var arr=[5,10,15];
function rect (arr,width)
{
Arr.sort (function (a,b) {return a-b;});
var len = arr.length;
var temp = arr[0];
var w = null;
var h = null;
for (var i = 0; i < len; i++)
{
if ((temp + i)!= Arr[i])
{
w = i;
if (len% w!= 0)
return false;
h = len/w;
Break
}
}
var r = width-w;
temp = R;
for (var i = w; i < Len; i++)
{
if (Arr[i]!= temp + i)
{
temp = R;
if (Arr[i]!= temp + i)
{
return false;
}
}
}
return true;
}
Alert (Rect (arr,6));
</script>
By no shame
<script>
var rows=6;
function ch (array) {
Array=array.sort (function (a,b) {return a-b;})
var n,c=0;
for (Var i=1;i<array.length;i++)
if (array[i]-array[i-1]==1)
C + +;
Else
Break
if (array.length% (c+1)!=0) return false;
for (Var i=1;i<array.length;i++)
{
N=ARRAY[I]-ARRAY[I-1];
if (n!=1 && n+c!=rows)
return false;
}
return true;
}
Alert (CH ([1,2,3]))
Alert (CH ([5,6,11,12,17,18,23,24]))
Alert (CH ([19,25,31]))
Alert (CH ([1,2,3,4,7,8]))
</script>
By the Qin emperor also love JS
<script>
var arr = [5,10,15];
var width = 6;
arr = Arr.sort (function (a,b) {return a-b});
var row = Math.ceil (arr[arr.length-1]-arr[0]+1)/width);
var col = Math.floor (arr.length/row);
check ();
function Check () {
for (var i=0;i<arr.length-1;i++) {
if (Arr[i+1]-arr[i]!=1 && i%col!=col-1 | | i%col==col-1 && arr[i+1]-arr[i]!= W idth-col+1) {
alert (false);
return;
}
}
alert (TRUE);
}
</script>