JSFiddle - React, Tailwind, and code Playground

by kentaromiura

JavaScript

Array.prototype.contains = function contains(item){

var length = this.length;
	if(length < 1) return false;
var from = Math.floor((arguments[1] || 0) -0);

	if(from === -Infinity) from = 0
	if(from < 0){
		from = length + from
	}
	if(from >= length || from > Math.pow(2, 32) -1) return false;

	var check = typeof item === 'number' && isNaN(item) ? isNaN : function(c){ return c === item };
  

	for(var i=from; i < length; i++)
		if(check(this[i])) return true;
	return false;
}

Array.prototype.contains = function (c){
    return function contains(item){
        console.log('<<', this, item, arguments[1], '>>')
        var result = c.apply(this, arguments);
        console.log('^ ', result, '\n');
        return result
    };
}(Array.prototype.contains);

$ERROR = alert;
Test262Error= Error;

var fromIndexTrap = {
    valueOf: function () {
        $ERROR('Should not try to call ToInteger on valueOf');
    }
};

var badLength = {
    length: Symbol(),
    get 0() {
        $ERROR('Should not try to get the zeroth element');
    }
};

Array.prototype.contains.call(badLength, 'a', fromIndexTrap);