All files / engine/Source/Scene/GltfPipeline addToArray.js

100% Statements 7/7
100% Branches 6/6
100% Functions 1/1
100% Lines 7/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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                        148x 148x 20x 20x 4x       144x 144x        
 
 
/**
 * Adds an element to an array and returns the element's index.
 *
 * @param {Array} array The array to add to.
 * @param {object} element The element to add.
 * @param {boolean} [checkDuplicates=false] When <code>true</code>, if a duplicate element is found its index is returned and <code>element</code> is not added to the array.
 *
 * @private
 */
function addToArray(array, element, checkDuplicates) {
  checkDuplicates = checkDuplicates ?? false;
  if (checkDuplicates) {
    const index = array.indexOf(element);
    if (index > -1) {
      return index;
    }
  }
 
  array.push(element);
  return array.length - 1;
}
 
export default addToArray;