Beta

File/Folder JSON Tree Formatting

Description
Loading description...
JSON
Algorithms
View
AllIssues6QuestionsSuggestionsShow Resolved
  • Please sign in or sign up to leave a comment.
  • Voile Avatar

    The random tests are not random at all, they just shuffles the same input and run multiple times.

    Also, mutating the input breaks all the tests, because there are no fixed tests.

    • gelus Avatar

      Additional random tests have been added.

      Mutating the input has been addressed via coppying the randomized array and create a fixed structure from it.

      Issue marked resolved by gelus 15 months ago
  • Blind4Basics Avatar

    Hi,

    • the initial solution contains two typos: ..., typed; ... -> ..., type: ...

    • I'm getting this with the full test suite:

      test.ts:20:43 - error TS2554: Expected 1 arguments, but got 2.
      
      20         if(n.type === 'folder') format(ar,n);
                                                   ~
      
  • Unnamed Avatar
    • gelus Avatar

      Oooh, that's funny. Quite cheeky.

      I've adjusted the tests to account of manipulation of the original array.

      Issue marked resolved by gelus 15 months ago
  • Voile Avatar
    expected { name: 'root', type: 'folder', …(1) } to deeply equal { name: 'root', type: 'folder', …(1) }
    

    Please add chai.config.truncateThreshold = 0; to the test code, otherwise the expected and actual values are hidden.

  • mortonfox Avatar

    Error when submitting solution:

    TSError: ⨯ Unable to compile TypeScript:
    test.ts:21:49 - error TS2554: Expected 1 arguments, but got 2.
    
    21         if(arr[i].type === 'folder') format(arr,arr[i]);
                                                       ~~~~~~
    
        at createTSError (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:859:12)
        at reportTSError (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:863:19)
        at getOutput (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:1077:36)
        at Object.compile (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:1433:41)
        at Module.m._compile (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:1617:30)
        at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
        at Object.require.extensions.<computed> [as .ts] (/workspace/default/node_modules/.pnpm/ts-node@10.9.1_ewfw2lwfc3dwdvz7r6yz2ssqyi/node_modules/ts-node/src/index.ts:1621:12)
        at Module.load (node:internal/modules/cjs/loader:1037:32)
        at Function.Module._load (node:internal/modules/cjs/loader:878:12)
        at Module.require (node:internal/modules/cjs/loader:1061:19)
        at require (node:internal/modules/cjs/helpers:103:18)
        at Object.exports.requireOrImport (/workspace/default/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/nodejs/esm-utils.js:53:16)
        at async Object.exports.loadFilesAsync (/workspace/default/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/nodejs/esm-utils.js:100:20)
        at async singleRun (/workspace/default/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/cli/run-helpers.js:125:3)
        at async Object.exports.handler (/workspace/default/node_modules/.pnpm/mocha@10.2.0/node_modules/mocha/lib/cli/run.js:370:5)
    

    What is the second argument to format() for ?

  • Voile Avatar

    It is safe to assume that all objects in the flat array will have parent fields that match a folder name in the same array, OR be set to 'root' if it is to be placed under the returned root level FileFolderObject.

    This is insufficient; for example,

    [
      { name:'folder', parent:'root',    type:'folder' },
      { name:'folder1', parent:'folder2', type:'folder' },
      { name:'folder2', parent:'folder1', type:'folder' },
    ]
    

    would be valid in this definition but does not form a valid tree.