You could pass an arg to the function -- pathsToTry, use its length as the termination condition, and .shift() the next path to try. The initial call would pass STORAGE_PATHS_.slice() -- a copy. The performance/memory overhead vs. index is negligible compared to spawning a child adb process, and IMHO it reads nicer.