To share the refactored code, change the anonymous function here as follows:

````
        function (file1, file2) {
            var ext1 = file1.name.split('.').pop(),
                ext2 = file2.name.split('.').pop(),
                cmpExt  = ext1.localeCompare(ext2); 
            
            if (cmpExt === 0) {
                return _filenameSort(file1, file2);
            } else {
                return cmpExt;
            }
        },
````