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 arr1 = arr;
    const arr2 = [];
    const arr3 = [];
    const res = [];
    for (let i = 0; i < arr1.length; i++) {
      if (arr1[i] === -1) { arr3.push(i); } else arr2.push(arr1[i]);
    }
    for (let i = 0; i < arr2.length - 1; i++) {
      for (let j = 0; j < arr2.length - 1; j++) {
        if (arr2[j] > arr2[j + 1]) {
          const z = arr2[j];
          arr2[j] = arr2[j + 1];
          arr2[j + 1] = z;
        }
      }
    }
    let s = 0;
    for (let i = 0; i < arr1.length; i++) {
      let k = 0;
      for (let j = 0; j < arr3.length; j++) {
        if (arr3[j] === i) {
          res.push(-1);
          k = 1;
        }
      }
      if (k === 0) {
        res.push(arr2[s]);
        s++;
      }
    }
    return res;
  }
  
  module.exports = sortByHeight;
  