var stringAlphanumericalOne = [' ','1','a'];
var stringAlphanumericalTwo = ['img ','img1','imga', 'imgz'];
var stringAlphanumericalThree = ['img 99','img199','imga99', 'imgz99'];
console.log( stringAlphanumericalOne.sort(naturalSort) );
console.log( stringAlphanumericalTwo.sort(naturalSort) );
/* in the call below it fails! order should be ["img 99", "img199", "imga99", "imgz99"] */
console.log( stringAlphanumericalThree.sort(naturalSort) );
var stringAlphanumericalOne = [' ','1','a']; var stringAlphanumericalTwo = ['img ','img1','imga', 'imgz']; var stringAlphanumericalThree = ['img 99','img199','imga99', 'imgz99'];
console.log( stringAlphanumericalOne.sort(naturalSort) ); console.log( stringAlphanumericalTwo.sort(naturalSort) ); /* in the call below it fails! order should be ["img 99", "img199", "imga99", "imgz99"] */ console.log( stringAlphanumericalThree.sort(naturalSort) );
see the live demo on http://jsbin.com/hihoqulediyi/1/edit?js,console