forked from root/public
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
…
|
||
---|---|---|
.. | ||
README.md |
README.md
Collections
Instructions
Write a bunch of functions which converts data from one type to another:
arrToSet
: fromArray
toSet
.arrToStr
: fromArray
tostring
.setToArr
: fromSet
toArray
.setToStr
: fromSet
tostring
.strToArr
: fromstring
toArray
.strToSet
: fromstring
toSet
.mapToObj
: fromMap
toObject
.objToArr
: fromObject
toArray
.objToMap
: fromObject
toMap
.arrToObj
: fromArray
toObject
.strToObj
: fromstring
toObject
.
Finally, write a function named superTypeOf
that unlike typeof
returns a specific values for advanced types like Map
and Set
.
Examples
const str = 'hello'
const arr = [1, 2, 1, 3]
const obj = { x: 45, y: 75, radius: 24 }
const set = new Set()
const map = new Map()
set.add(1)
set.add(2)
set.add(1)
set.add(3)
map.set('a', 1)
map.set('b', 2)
map.set(3, 'c')
map.set(4, 'd')
arrToSet(arr) // -> Set { 1, 2, 3 }
arrToStr(arr) // -> '1213'
setToArr(set) // -> [1, 2, 3]
setToStr(set) // -> '123'
strToArr(str) // -> ['h', 'e', 'l', 'l', 'o']
strToSet(str) // -> Set { 'h', 'e', 'l', 'o' }
mapToObj(map) // -> { a: 1, b: 2, '3': 'c', '4': 'd' }
objToArr(obj) // -> [45, 75, 24]
objToMap(obj) // -> Map { 'x' => 45, 'y' => 75, 'radius' => 24 }
arrToObj(arr) // -> { '0': 1, '1': 2, '2': 1, '3': 3 }
strToObj(str) // -> { '0': 'h', '1': 'e', '2': 'l', '3': 'l', '4': 'o' }
superTypeOf(map) // -> 'Map'
superTypeOf(set) // -> 'Set'
superTypeOf(obj) // -> 'Object'
superTypeOf(str) // -> 'String'
superTypeOf(666) // -> 'Number'
superTypeOf(NaN) // -> 'Number'
superTypeOf(arr) // -> 'Array'
superTypeOf(null) // -> 'null'
superTypeOf(undefined) // -> 'undefined'
superTypeOf(superTypeOf) // -> 'Function'