Created
August 3, 2023 14:01
-
-
Save kdclaw3/4edd7276590a5e177de75c44fc862e62 to your computer and use it in GitHub Desktop.
MentorAPM Jr. Dev Interview Cheat Sheet
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(async function () { | |
const { layers } = await (await fetch('https://.../arcgis/rest/services/.../MapServer?f=pjson')).json(); | |
const layersById = layers.reduce((acc, item) => { | |
acc[item.id] = item; | |
return acc; | |
}, {}); | |
let usedIcons = []; | |
const icon = () => { | |
const generateRandomIcon = () => { | |
const rn = Math.floor(Math.random() * (Math.floor(9983) - Math.ceil(9728) + 1)) + Math.ceil(9728); | |
return String.fromCharCode(rn); | |
}; | |
let newIcon = generateRandomIcon(); | |
while (usedIcons.includes(newIcon)) { | |
newIcon = generateRandomIcon(); | |
} | |
usedIcons.push(newIcon); | |
return newIcon; | |
}; | |
const recurseLayer = (layerId, recursionLevel) => { | |
let layer = layersById[layerId]; | |
console.log('\t'.repeat(recursionLevel) + icon() + ' ' + layer.name); | |
for (let i=0, l=(layer.subLayerIds || []).length; i<l; i++) { | |
const subLayerId = layer.subLayerIds[i]; | |
recurseLayer(subLayerId, (recursionLevel+1)); | |
} | |
}; | |
for (let id in layersById) { | |
let layer = layersById[id]; | |
if (layer.parentLayerId === -1) { | |
recurseLayer(id, 0); | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment