Created
May 27, 2021 05:22
-
-
Save xwartz/7bf9ac8ee97160e125b9ddcefe0dfcf2 to your computer and use it in GitHub Desktop.
Interview-node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* Create a function that meets the following requirements: | |
* - Read files and folders from the specified directory. | |
* - Collects metadata about files or folders and returns it as an array. | |
* - Note whether the file has read access. | |
* | |
* 创建一个符合下述要求的函数: | |
* - 读取指定目录下的文件或文件夹,包含子文件夹 | |
* - 收集文件的元信息并作为数组返回 | |
* - 注意文件或文件夹的权限 | |
* | |
* Example: | |
* readAllFiles('/usr/local/bin') | |
* --> [{ type: 'folder', pwd: '/usr/local/bin/node', name: 'node' }] | |
* | |
**/ | |
type FileMetadata<T> = { | |
pwd: string | |
name: string | |
} & T | |
type File = FileMetadata<{ | |
size: number | |
type: 'file' | |
}> | FileMetadata<{ | |
type: 'folder' | |
}> | |
const readAllFiles = (path: string): File[] => {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment