lib/utils/promiseUtils/mapAfterAllReturn.js
function mapAfterAllReturn(arr, mapper, returnValue) {
  const results = new Array(arr.length);
  let containsPromise = false;

  for (let i = 0, l = arr.length; i < l; ++i) {
    results[i] = mapper(arr[i]);

    if (isPromise(results[i])) {
      containsPromise = true;
    }
  }

  if (containsPromise) {
    return Promise.all(results).then(() => returnValue);
  } else {
    return returnValue;
  }
}
function mapAfterAllReturn(arr, mapper, returnValue) {
  const results = new Array(arr.length);
  let containsPromise = false;

  for (let i = 0, l = arr.length; i < l; ++i) {
    results[i] = mapper(arr[i]);

    if (isPromise(results[i])) {
      containsPromise = true;
    }
  }

  if (containsPromise) {
    return Promise.all(results).then(() => returnValue);
  } else {
    return returnValue;
  }
}
function mapAfterAllReturn ( arr , mapper , returnValue ) { const results = new Array ( arr . length ) ; let containsPromise = false ; for ( let i = 0 , l = arr . length ; i < l ; ++ i ) { results [ i ] = mapper ( arr [ i ] ) ; if ( isPromise ( results [ i ] ) ) { containsPromise = true ; } } if ( containsPromise ) { return Promise . all ( results ) . then ( ( ) => returnValue ) ; } else { return returnValue ; } }
Map `arr` with `mapper` and after that return `returnValue`. If none of the mapped values is a promise, return synchronously for performance reasons.
Map arr with mapper and after that return returnValue . If none of the mapped values is a promise return synchronously for performance reasons .