Using JavaScript, I have an array of file paths that I'm looping through and checking. If the current item is a folder, I want to bump it to the back of the line and move on to the next item. The end result would be files in front, folders after the last file.
I know this should be easy, but I've been fighting with it for 2 days. I've tried various versions of the following code with no success. For the purpose of this project, I'm assuming it's a folder if there's no period present in the filename.
function sortArray(array) {
console.log('Original array: ' + array);
var z = array.length;
console.log('Array length is ' + z);
for(i = 0; i < z-1; i++)
{
var n = array.indexOf(array[i]);
if (array[i].indexOf('.') === -1)
{
console.log('Item is folder');
var fldr = array.splice(n, 1);
array.push(fldr);
}
}
console.log('Sorted array: ' + array);
}
.sort()and pass a comparator that compares by whether the elements have "." in the name (which is possible for folders too, of course, but whatever).