Blame view

node_modules/es5-ext/array/#/e-last-index-of.js 838 Bytes
f7563de62   Palak Handa   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
  'use strict';
  
  var toPosInt = require('../../number/to-pos-integer')
    , value    = require('../../object/valid-value')
  
    , lastIndexOf = Array.prototype.lastIndexOf
    , hasOwnProperty = Object.prototype.hasOwnProperty
    , abs = Math.abs, floor = Math.floor;
  
  module.exports = function (searchElement/*, fromIndex*/) {
  	var i, fromIndex, val;
  	if (searchElement === searchElement) { //jslint: ignore
  		return lastIndexOf.apply(this, arguments);
  	}
  
  	value(this);
  	fromIndex = arguments[1];
  	if (isNaN(fromIndex)) fromIndex = (toPosInt(this.length) - 1);
  	else if (fromIndex >= 0) fromIndex = floor(fromIndex);
  	else fromIndex = toPosInt(this.length) - floor(abs(fromIndex));
  
  	for (i = fromIndex; i >= 0; --i) {
  		if (hasOwnProperty.call(this, i)) {
  			val = this[i];
  			if (val !== val) return i; //jslint: ignore
  		}
  	}
  	return -1;
  };