Unique ids for nils and booleans in arrays.
This commit is contained in:
parent
28a3d22911
commit
5cf1d7bcc6
@ -26,3 +26,20 @@ Array >> bagOfWordsFor: sentenceArray [
|
|||||||
].
|
].
|
||||||
^ bagOfWords
|
^ bagOfWords
|
||||||
]
|
]
|
||||||
|
|
||||||
|
{ #category : #'*MiniDocs' }
|
||||||
|
Array >> replaceWithUniqueNilsAndBooleans [
|
||||||
|
| response |
|
||||||
|
(self includesAny: #(true false nil))
|
||||||
|
ifFalse: [ response := self ]
|
||||||
|
ifTrue: [ | newItem |
|
||||||
|
response := OrderedCollection new.
|
||||||
|
self do: [:item |
|
||||||
|
(item isBoolean or: [ item isNil ])
|
||||||
|
ifTrue: [ newItem := item asString, '-', (NanoID generate copyFrom: 1 to: 3) ]
|
||||||
|
ifFalse: [ newItem := item ].
|
||||||
|
response add: newItem.
|
||||||
|
].
|
||||||
|
].
|
||||||
|
^ response
|
||||||
|
]
|
||||||
|
@ -48,7 +48,7 @@ OrderedDictionary >> replaceNilsWith: aCharacter [
|
|||||||
|
|
||||||
{ #category : #'*MiniDocs' }
|
{ #category : #'*MiniDocs' }
|
||||||
OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [
|
OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [
|
||||||
| totalNils shortUID |
|
| totalNils shortUID newArray |
|
||||||
totalNils := self flattened asDataSeries countNils.
|
totalNils := self flattened asDataSeries countNils.
|
||||||
shortUID := [NanoID generate copyFrom: 1 to: 3].
|
shortUID := [NanoID generate copyFrom: 1 to: 3].
|
||||||
self associations doWithIndex: [:assoc :i | | subIndex |
|
self associations doWithIndex: [:assoc :i | | subIndex |
|
||||||
@ -58,21 +58,8 @@ OrderedDictionary >> replaceWithUniqueNilsAndBooleansStartingAt: anInteger [
|
|||||||
assoc value isBoolean
|
assoc value isBoolean
|
||||||
ifTrue: [ self at: assoc key put: assoc value asString, '-', subIndex ].
|
ifTrue: [ self at: assoc key put: assoc value asString, '-', subIndex ].
|
||||||
assoc value isDictionary ifTrue: [assoc replaceWithUniqueNilsAndBooleansStartingAt: i].
|
assoc value isDictionary ifTrue: [assoc replaceWithUniqueNilsAndBooleansStartingAt: i].
|
||||||
assoc value isArray ifTrue: [ | newArray|
|
assoc value isArray
|
||||||
newArray := (assoc value asDataSeries replaceNilsWith: 'nil-', shortUID value) asArray.
|
ifTrue: [ self at: assoc key put: (assoc value replaceWithUniqueNilsAndBooleans)]
|
||||||
(newArray includesAny: #(true false))
|
|
||||||
ifTrue: [ | response newItem |
|
|
||||||
response := OrderedCollection new.
|
|
||||||
self do: [ :item |
|
|
||||||
item isBoolean
|
|
||||||
ifTrue: [ newItem := item asString, '-', shortUID value]
|
|
||||||
ifFalse: [ newItem := item ].
|
|
||||||
response add: newItem.
|
|
||||||
].
|
|
||||||
newArray := response asArray.
|
|
||||||
].
|
|
||||||
self at: assoc key put: newArray
|
|
||||||
]
|
|
||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user