Nodejs Array Value tw_indexOf(val)

Here you can find the source of tw_indexOf(val)

Method Source Code

/**/*from  w w w .j  a v  a  2 s.  c o  m*/
 * Created by jzj on 16/1/30.
 */


// Array functions ..........
Array.prototype.tw_indexOf = function(val) {
    for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
    }
    return -1;
};
Array.prototype.tw_remove = function(val) {
    var index = this.indexOf(val);
    if (index > -1) {
        this.splice(index, 1);
    }
};

// traverse value
/**
 @param [initial number] v1
 @param [destination number] v2
 @param [0-1 number] t
 @return [current number]
 */
Math.tw_lerp = function(v1,v2,t) {
    return v1 + (v2-v1)*t;
};
/**
 @param [initial number] v1
 @param [destination number] v2
 @param [current number] v3
 @return [progress number]
 */
Math.tw_progress = function(v1,v2,v3) {
    return (v3-v1)/(v2-v1);
};

Related

  1. resize(newSize, defaultValue = 0)
    Array.prototype.resize = Array.prototype.resize || function(newSize, defaultValue = 0) {
        while (newSize > this.length) {
            this.push(defaultValue);
        this.length = newSize;
    };
    
  2. resizeMatrix(rowsSize, columnsSize, defaultValue = 0)
    Array.prototype.resizeMatrix = Array.prototype.resizeMatrix || function(rowsSize, columnsSize, defaultValue = 0) {
        while (rowsSize > this.length) {
            var row = [];
            row.resize(columnsSize, defaultValue);
            this.push(row);
        this.length = rowsSize;
    };
    
  3. superJoin(value)
    isNullOrEmpty=function(obj) {
        if (obj == undefined || obj == null || obj == "") {
            return true;
        else {
            return false;
    Array.prototype.superJoin=function(value){
    ...
    
  4. toggleValue(value)
    Array.prototype.toggleValue = function (value) {
        var index = this.indexOf(value);
        if (index === -1) {
            this.push(value);
        else {
            this.splice(index, 1);
    };
    ...
    
  5. trim(value)
    Array.prototype.trim = function (value) {
      var array = this.slice(0); 
      while (array.length > 0 && array[0] === value) {
        array.shift();
      while (array.length > 0 && array[array.length - 1] === value) {
        array.pop();
      return array;
    ...
    
  6. unset(value)
    Array.prototype.unset = function (value) {
        if (this.indexOf(value) !== -1) { 
            this.splice(this.indexOf(value), 1);
    };
    
  7. unset(value,isIndex)
    Array.prototype.unset = function(value,isIndex) {
      var isIndex = isIndex || 0;
      if (value == undefined) {
        this.length = 0;
        return this;
      for (var i = 0, j = 0, l = this.length; i < l; ++i) {
        if (!isIndex) {
          if (this[i] != value) { 
    ...
    
  8. unset(value,isIndex)
    Array.prototype.unset = function(value,isIndex) {
      var isIndex = isIndex || 0;
      if (value == undefined) {
        this.length = 0;
        return this;
      for (var i = 0, j = 0, l = this.length; i < l; ++i) {
        if (!isIndex) {
          if (this[i] != value) { 
    ...
    
  9. valueIndexOf(val)
    Array.prototype.valueIndexOf = function(val) {
      for (var i = 0; i < this.length; i++) {
        if (this[i] == val) return i;
      return -1;
    };