Author | Message |
---|---|
Amedrano
Posts: 80
|
Posted 20:22 Mar 07, 2017 |
I'm trying to dynamically create an object using the filepaths and hashkeys. Im using a for loop in the the readFiles() method but it seems like it is not even seeing/entering the for loop. Any ideas tips? |
prashantkk
Posts: 2
|
Posted 20:26 Mar 07, 2017 |
Is it ok if we do not use crypto? |
Amedrano
Posts: 80
|
Posted 20:29 Mar 07, 2017 |
Yeah I don't think crypto is necessary
|
mkuko
Posts: 13
|
Posted 20:29 Mar 07, 2017 |
I might not fully understand what you are saying but if I am i believe that function that's inside the readfile already iterates through the files so the content that's passed in to that function is for each file in the directory, you don't need a for loop inside the function if I understand your post properly. |
HeroVega
Posts: 8
|
Posted 20:34 Mar 07, 2017 |
This was my thinking for that part: I created the object and in the readFiles() method you have the option to pass in a filename parameter. dir.readFiles(directory, (err, content, filename, next) =>{ from here all you need to do is use the filename and the content to make the hashes and add that to the object |
Amedrano
Posts: 80
|
Posted 20:38 Mar 07, 2017 |
Ok Thank you! I believe I understand that. What's the "Assume" Syntax? |
HeroVega
Posts: 8
|
Posted 20:45 Mar 07, 2017 |
That's just so that the variables dir and directory would make sense when I wrote the function. It's not psuedocode, I'm just literally saying to assume this variable equals this value so the example makes sense. |
Amedrano
Posts: 80
|
Posted 21:11 Mar 07, 2017 |
So I must be doing something wrong because its not adding the information I'm passing to the object let files = {} <---- global variable in my dir.readFiles() method { console.log('hashKey of ' + filename + ' is: ', hashKey); <--- this prints out Object.assign(files, {hashKey: filename}) < --- this does nothing } I'm sure something is wrong with my syntax but not sure what. Thanks. |
HeroVega
Posts: 8
|
Posted 21:29 Mar 07, 2017 |
Try using shorthand object notation: then after readFiles just do: |
Amedrano
Posts: 80
|
Posted 21:47 Mar 07, 2017 |
Thanks I appreciate the help but for some reason its not adding it to the 'files' object. |