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 sorted = [...arr].sort((a, b) => a - b);
  
    const num = sorted.lastIndexOf(-1);
    const newArr = sorted.slice(num + 1);
  
    let counter = 0;
    const result = arr.map((x) => {
      let int;
  
      if (x === -1) int = x;
      else {
        int = newArr[counter];
        counter += 1;
      }
  
      return int;
    });
    return result;
  }
  
  module.exports = sortByHeight;
  