Constructor
# new Sorter(toBeSorted)
Parameters:
Name | Type | Description |
---|---|---|
toBeSorted |
Object
|
pass the object to be sorted |
Properties:
Name | Type | Description |
---|---|---|
_toBeSorted |
String
|
the object to be sorted |
when the object has values that are of any other type than string this will throw an Error
Example
//succeeds
const sorter = new Sorter({
"key":"value",
"key1":"value1"
})
// fails
const sorter = new Sorter({
"key":true
})
// fails
const sorter = new Sorter({
"key":1
})
// fails
const sorter = new Sorter({
"key":["anything","other","than","a","normal","string","in","value","will","fail"]
})
Methods
# sort() → {Object}
sorts the object set in the _toBeSorted as per the key length(and value length if key length is same)
- returns the fully sorted array sortedArray
Object
Example
const sorter = new Sorter({
"second":"value",
"first":"value1",
"samelength1":"longer value",
"samelength2":"small value"
})
const output = sorter.sort()
console.log(output)
// {
// "first":"value1",
// "second":"value",
// "samelength2":"small value",
// "samelength1":"longer value"
// }