传送门 The k-th Largest Group Time Limit: 2000MS Memory Limit: 131072K Total Submissions: 8690 Accepted: 2847 Description Newman likes playing with cats. He possesses lots of cats in his home. Because the number of cats is really huge, Newman wants
//判断数组array中是否包含元素obj的函数,包含则返回true,不包含则返回false function array_contain(array, obj){ for (var i = 0; i < array.length; i++){ if (array[i] == obj)//如果要求数据类型也一致,这里可使用恒等号=== return true; } return false; }
判断数组中是否有重复元素,最容易想到的方法是使用2重循环,逐个遍历,比较,但是这个是最慢,最笨的方法,百度得出了更好的方法. var ary = new Array("111","22","33","111"); var nary=ary.sort(); for(var i=0;i<ary.length;i++){ if (nary[i]==nary[i+1]){ alert("数组重复内容:"+na
Array.prototype.indexOf = function (val) {//判断数组是否存在某个值,如果存在返回该值对应的索引,否则返回-1 for (var i = 0; i < this.length; i++) { if(typeof val === 'object' && typeof this[i]==='object'){ var str1 = JSON.stringify(val); var str2 = JSON.stringify(this[i]); i
/* 判断数组中是否存在 var somearray = ["mon", "tue", "wed", "thur"] somearray.exists ("tue"); //somearray will return true */ Array.prototype.exists = function (val) { for (var i = 0; i < this.length; i++) { if