Before you all baulk at nesting a method within a loop, this is an example where I truly see no other way. Though, I will entertain other suggestions.
Anyways, I'm using the Dropbox.js SDK for their API. I am looking in a directory for files given based on extension given the following list and path:
FILE_EXTENSIONS = [".py",".js",".cpp",".html",".h"];
PATH = "/Developer";
My code is as follows:
var counts = [];
look_for_files(PATH, FILE_EXTENSIONS);
function look_for_files(directory_path, file_extensions){
for (var i = 0; i < file_extensions.length; i++){
current_file = file_extensions[i];
client.search(PATH, current_file, function(error, count){
if(error){
return showError(error);
}
console.log(current_file); // Problem is here.
console.log(count.length);
counts.push(count.length);
});
}
};
Now, when I log the (count.length) I get the following output:
.h
88
.h
607
.h
665
.h
180
.h
410
The numbers are changing, but the current_file is not, even though it's being passed into the method. I have no idea why. This is one of my first experiences programming in javascript (I come from an OOP background), but I am lost. Could someone please help explain?
Thanks