“Cannot read property ‘length’ of undefined”
This is a test error log coming from the fact that your function is returning
undefined. There is a test trying to access the
length property of
undefined – your return value – to verify your result.
"Why does my function return
To return a value other than the default, a function must have a
return statement that specifies the value to return. A function without a return statement will return a default value. In the case of a constructor called with the
new keyword, the default value is the value of its
this parameter. For all other functions, the default return value is
- MDN > Functions
So your bubbleSort
while loop is working alright, but your function is not returning the sorted array.