📝 Added sandbox (code sketchbook)
This commit is contained in:
parent
b475595f7f
commit
b5daf18b1a
142 changed files with 100702 additions and 0 deletions
19
sandbox/flatten_js_obj/deflate.js
Normal file
19
sandbox/flatten_js_obj/deflate.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
'use strict'
|
||||
// flattens javascript object and returns an array of all values
|
||||
const deflateObject = (obj) => {
|
||||
const result = []
|
||||
const deflate = (obj) => {
|
||||
return Object.keys(obj).forEach(key => {
|
||||
return typeof obj[key] === 'object' && obj[key]
|
||||
? deflate(obj[key])
|
||||
: typeof obj[key] === 'function'
|
||||
? result.push(obj[key]())
|
||||
: obj[key]
|
||||
? result.push(obj[key])
|
||||
: ''
|
||||
|
||||
})
|
||||
}
|
||||
deflate(obj)
|
||||
return result
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue