Skip to content

Instantly share code, notes, and snippets.

@kdclaw3
Created August 3, 2023 14:01
Show Gist options
  • Save kdclaw3/4edd7276590a5e177de75c44fc862e62 to your computer and use it in GitHub Desktop.
Save kdclaw3/4edd7276590a5e177de75c44fc862e62 to your computer and use it in GitHub Desktop.
MentorAPM Jr. Dev Interview Cheat Sheet
(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