MCPcopy Create free account
hub / github.com/codecombat/codecombat / downTheChain

Function downTheChain

app/core/utils.js:99–113  ·  view source on GitHub ↗
(obj, keyChain, newValue)

Source from the content-addressed store, hash-verified

97// Walk a key chain down to the value. Can optionally set newValue instead.
98// Same as in world_utils, but don't want mutual imports
99const downTheChain = function (obj, keyChain, newValue) {
100 if (newValue == null) { newValue = undefined }
101 if (!obj) { return null }
102 if (!_.isArray(keyChain)) { return obj[keyChain] }
103 let value = obj
104 while (keyChain.length && value) {
105 if ((newValue !== undefined) && (keyChain.length === 1)) {
106 value[keyChain[0]] = newValue
107 return newValue
108 }
109 value = value[keyChain[0]]
110 keyChain = keyChain.slice(1)
111 }
112 return value
113}
114
115const countries = [
116 { country: 'united-states', countryCode: 'US', ageOfConsent: 13, addressesIncludeAdministrativeRegion: true },

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected