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 z = arr;
    const x = [];
    for (let i = 0; i < z.length; i++) {
      if (z[i] !== -1) {
        x.push(z[i]);
      }
    }
    x.sort((a, b) => a - b);
    for (let i = 0; i < z.length; i++) {
      if (z[i] !== -1) {
        z.splice(i, 1, x[0]);
        x.splice(0, 1);
      }
    }
    return z;
  }
  
  module.exports = sortByHeight;
  