79392181

Date: 2025-01-27 21:15:36
Score: 2
Natty:
Report link

You don't stop the original while loop from continuing, even after the folder is found in a deeper level of the recursion.

To fix this issue, you need to handle the result of the recursive call and break out when a match is found like this:

function buscarCarpeta(origen, curso) {
    curso = curso.toString();
    var folders = origen.getFolders();
    
    while (folders.hasNext()) {
        var folder = folders.next();
        var name = folder.getName();
        var scr = name.search(curso);
        
        if (scr > -1) {
            Logger.log("Encontrado");
            return folder; // Exit on folder found
        }
        
        // Recursive call on subfolders
        var found = buscarCarpeta(folder, curso);
        if (found) {
            return found; // Return the folder
        }
    }
    
    return null; // no folder founded
}

Hope this was helpfull; happy coding!

Reasons:
  • RegEx Blacklisted phrase (2): Encontrado
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Andrea