How do I make the sumFileSizes function?

  • 0
    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 size of a file, use the getFileSize (filename, cb) function.

    let fileSizes = {
      testFile1: 65,
      testFile2: 48,
    }
    
    function getFileSize(filename, cb) {
      setTimeout(() => cb(fileSizes[filename]), Math.random() * 500);
    }
    
    function sumFileSizes(filename1, filename2, cb) {
      //Ваш код...
    }
    JavaScript Cora Taylor, Jan 24, 2020

  • 1 Answers
  • 0
    const fileSizes = {
    testFile1: 65,
    testFile2: 48,
    }

    function getFileSize(filename, cb) {
    setTimeout(() => cb(fileSizes[filename]), Math.random() * 500);
    }

    function sumFileSizes(filename1, filename2, cb) {
    let s = 0
    const ss = (sss) => s += sss
    getFileSize(filename1, ss)
    getFileSize(filename2, ss)
    setTimeout(() => cb(s), 505)
    }

    sumFileSizes('testFile1', 'testFile2', (k) => console.log(k))




    : ~ |
    Anonymous

Your Answer
To place the code, please use CodePen or similar tool. Thanks you!