Friends, help with the task.
I need to write a function that takes the names of two files and calls the function passed in the third parameter and passes it the sum of their sizes as the first argument.
To get the file frame, you need to use the getFileSize (filename, cb)
function.
Here is the data:
let fileSizes = {
testFile1: 65,
testFile2: 48,
}
function getFileSize(filename, cb) {
setTimeout(() => cb(fileSizes[filename]), Math.random() * 500);
}
function sumFileSizes(filename1, filename2, cb) {
//**code here**
}
I wrote a solution that passes the tests. But I don't like it.
Here it is:
function sumFileSizes(filename1, filename2, cb) {
getFileSize(filename1, (size1)=> {
getFileSize(filename2, (size2)=> {
cb(size1 + size2);
});
})
}
Can you write something better and shorter? And without using a promise
or await
.
I'll be very thankful