Skip to content

Instantly share code, notes, and snippets.

@xwartz
Created May 27, 2021 05:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xwartz/7bf9ac8ee97160e125b9ddcefe0dfcf2 to your computer and use it in GitHub Desktop.
Save xwartz/7bf9ac8ee97160e125b9ddcefe0dfcf2 to your computer and use it in GitHub Desktop.
Interview-node
/**
*
* 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