Algoritma yang digunakan untuk mengubah kumpulan dictionary menjadi flat.
jsconst dict = {key1: 2,key2: 23,nested: {a: 34,b: 24,nested: {c: 'qwerty',d: 'asdf'}}}function flatDict(dictionary) {let initDict = {}function dictHelper(dict, propName) {if (typeof dict !== 'object') {initDict[propName] = dictreturn}for (const prop in dict) {// if (propName == '') {dictHelper(dict[prop], prop)// } else {// dictHelper(dict[prop], propName+'.'+prop)// }}}dictHelper(dictionary, '')return initDict}flatDict(dict) // { key1: 2, key2: 23, a: 34, b: 24, c: 'qwerty', d: 'asdf' }
TIme Complexity: : O(log2(n)) atau logartichmic