Enhance function that justifies text
Few improvements which can be seen right away are in this part

let splitStr = [];
for (let i = 0; i &lt; str.split(' ').length; i++) {
  if (str.split(' ')[i].length) {
    splitStr.push(str.split(' ')[i])
  }
}


Can be re-written as:

const tempArray = str.split(' ')
let splitStr = tempArray.filter(data =&gt; data.length)



You can use Array.filter directly here.
Str.split(' ') is getting repeated at lot. So better save it in some variable and then re-use
Comparison inside if (length === 0) in other portions can be written as if(!length) since 0 is falsy