last day (16 days later) » 

9:56 PM
you there?
 
tex
I have a slight interruption - will get back to you shortly.
 
kk
ok so here is the initial output without the map function
why doesnt it show the preview lol
and here is the typeof files. turns out its a pending promise
heres the first image of the initial output without the map function
yeah so it doesnt seem to be awaiting result
 
tex
10:51 PM
apologies for the interruption. I'm looking into it now.
@oldboy I just edited the code again, assigning the initial await Promise.all to an intermediate variable.
 
i actually have a working version that i just wrote
 
tex
Nice!
 
but what i dont like about the version i wrote is that i end up taking the global results and parsing it again. i would prefer if everything was taken care of in the scan() although im not sure how practical that is?
ok so here is the working version i just wrote
im gonna edit my Q and add it thereto
// Initiate scan sequence.
async function initiateScan(exts) {
let
[config, data] = await Promise.all([
readJson('./config.json'),
readJson('./data.json')
]),
results = await Promise.all(
// config.drives.map(drive => scan(drive, exts))
['K:', 'D:'].map(drive => scan(drive, exts))
)

// console.log(results)
for (const drive of results) {
// console.log(drive)
let root = false
for (const file of drive) {
if (!root) root = parse(file.path).root.slice(0,-1)
if (!data[root][file.type]) data[root][file.type] = []
 
tex
Tough. My solution also iterated through the files collection a second time. It should be possible to do it in one pass. I'll think about it.
side note: I deleted a bunch of my comments on my answer to clean things up a bit.
A solution involving a single pass would need to be based on reduce rather than map.
 
it should be possible, right? the only tricky part is the scan() function which is dealing with arrays partly due to the fact that the promises therein return iterables/arrays, dont they?
 
tex
11:06 PM
Dunno, Roaming's map-based solution might work, but I'm too much of a purist to mutate the results object inside a map operation. Definitely not an approach I'd take in production, except as a last resort.
The tricky part is that Promise.all works on an array of promises, only. I haven't determined whether it's possible to do in one pass (without mutating the results object).
 
im not even sure what you mean by mutating the results object inside the map operation. on which line does he do that?
i did notice a problem with my approach
sometimes data[root][file.type] is going to contain preserved data from the last scan, so i cant just push new data to it. i have to somehow clear each of the file.type arrays first, before i push anything to it
 
tex
all over the place :D He mentions it's not clean in his preamble. Everywhere he assigns something to results, he's mutating it. I don't want to be too critical, and if it works, that's cool. It's just not how I'd choose to do it unless there were no other feasible options.
I think my code should be fixed up by now - I'd forgotten to make the cb inside the first map async. If it doesn't work, I'd want to set up some tests to try it out locally so you're not acting as my long-distance REPL :D
 
figured out how to do it for (const [i, file] of drive.entries()) { if (!i) :)
ahhhh i see what u meant
true that
cb?
repl? lol
all these acronyms flying way over my head lol
 
tex
anyway, looking at his solution a second time, it is sort of ingenious. He seems to have managed to get it all done in one pass by subverting map a bit, so cheers to him if it works.
repl = read, evaluate, print, loop (it's an interface into which you can enter code and run it immediately to see the results).
cb = callback. I was referring to the callback function I passed to the first map operation.
 
11:21 PM
ohhhh lol
 
tex
That needed to be async in order for the Promise.all wrapper around it to actually do anything.
 
yeah i havent been able to take a thorough look at his answer just yet cuz ive been working on my own, but i will be taking another look right after this
ohhh
right right
hold on let me save my solution, then ill test ur modification
 
tex
no worries. I will probably try to set up a mock locally so I can run it myself. Don't want to interrupt your creative process.
 
its all good. i gotta wrap it up here soon anyways. ok so ive saved my solution. im gon test urs right now
fuck i accidentally scanned all of my drives for txt and m2ts files instead of switching config.drives to ['D:', 'K:'] lol
do u know how to cancel the process? just exit electron?
nm it finished with an error
acc is not defined. in which scope should i declare it?
 
tex
damn, should be here: ` (file) => {`
should be:
` (acc, file) => {`
 
11:34 PM
kk
im getting this error
Iterator value undefined is not an entry object
on the const results = Object.fromEntries line
 
tex
damn, I love it when my untested code works the first time. :D
 
hahah
 
tex
No worries - I'll set up a mock so I can play around with it. Take a look at Roaming's solution when you get a chance. It may be the answer to doing everything in one pass.
Good luck working it out - I have to jet, as well.
 
ive developed the habit of testing my code literally almost every single modification cuz my code would always have bugs by the time i finished writing it and it is always so much harder weeding thru the whole code afterwards
thanks bro
really appreciate you taking the time to help!!
happy new year!
 
tex
same to ya!
@oldboy Me too, but I get lucky sometimes, and I savour those moments.
damn, didn't mean to @ you. Take care!
If you do want to test it again at some point in the future, I believe I fixed that previous error. I think it was due to the change you made in this edit: stackoverflow.com/revisions/59594961/7
 
11:52 PM
i edited it a couple times, and it doesnt show me which edit it was. i will def test it again when i get some more free time 🤓
 

  last day (16 days later) »