Add tags

Add tags to the following comment

JavaScript@Firebugコンソールで。少し意訳しました。

>>> new Array(1,5,4,2).check();
true
>>> new Array(1,2,3).check();
true
>>> new Array(825,102,811,140,812,125,263).check();
false
>>> new Array(824,102,811,140,810,155,263).check();
true
>>> new Array(5,4,3,2,1).check();
true
>>> new Array(4,2,5,3,1).check();
false
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Array.prototype.check = function() {
  var upper = Number.MAX_VALUE;
  var lower = Number.MIN_VALUE;
  for (var i = 0; i < this.length; i++) {
    if ( (upper <= this[i]) || (this[i] <= lower) )
      return false;
    if (this[i] < this[i+1])
      lower = this[i];
    else
      upper = this[i];
  }
  return true;
};

Add tags

The input will be splited to tags with space.

Index

Feed

Other

Link

Pathtraq

loading...