create _.cloneDeep()
2022年5月1日小于 1 分钟
_.cloneDeep()
create Question
Object.assign()
could be used to do shallow copy, while for recursive deep copy, _.cloneDeep could be very useful.
Can you create your own _.cloneDeep()
?
The lodash implementation actually covers a lot of data types, for simplicity, your code just need to cover
- primitive types and their wrapper Object
- Plain Objects (Object literal) with all enumerable properties
- Array
There is built-in structuredClone() now, but don't use this to practice
Code
function cloneDeep(data) {
// your code here
}