text: /**
   * Given an array with heights, sort them except if the value is -1.
   *
   * @param {Array} arr
   * @return {Array}
   *
   * @example
   * arr = [-1, 150, 190, 170, -1, -1, 160, 180]
   *
   * The result should be [-1, 150, 160, 170, -1, -1, 180, 190]
   */
  function sortByHeight(arr) {
    const indexes = [];
    const numbers = [];
  
    arr.map((a, index) => (a === -1 ? indexes.push(index) : numbers.push(a))).sort();
  
    const sortNumbers = numbers.sort((b, d) => b - d);
  
    for (let i = 0; i < indexes.length; i++) {
      sortNumbers.splice(indexes[i], 0, -1);
    }
  
    return sortNumbers;
  }
  
  module.exports = sortByHeight;
  