var str = "Compare with your a solution"; function findShort(s){ return Math.min.apply(null, s.split(' ').map(w => w.length)); } function sortNumber(a,b) { return a.length - b.length } console.log(findShort(str)) console.log(str.split(' ').sort(sortNumber)[0]) console.log(str)