Write a function called "getLengthOfShortestElement".
Given an array, "getLengthOfShortestElement" returns the length of the shortest string in the given array.
Notes: * It should return 0 if the array is empty.
My code:
function getLengthOfShortestElement(arr) {
if (arr.length === 0) return 0;
return arr.sort(function(a, b){
return a.length> b.length;
}).unshift();
}
getLengthOfShortestElement(['one', 'two', 'three']); // 3
Why is it not passing the test that it should "handle ties" by returning only the first instance of the shortest element. Also, is there a better way of making an empty array return 0?