Skip to content

Instantly share code, notes, and snippets.

@mariogillazaro
Last active April 9, 2018 01:09
Show Gist options
  • Save mariogillazaro/d2ef830af71944ac0c484fdcae49d3ac to your computer and use it in GitHub Desktop.
Save mariogillazaro/d2ef830af71944ac0c484fdcae49d3ac to your computer and use it in GitHub Desktop.
// Ejercicio #1
function convertObjectToArray(obj) {
const arrayRepresentation = [];
for (key in obj) {
const value = obj[key];
const pair = [key, value];
arrayRepresentation.push(pair);
}
return arrayRepresentation;
};
// Ejercicio #2
function getElementOfArrayProperty(obj, key, index) {
if (!obj) return undefined;
if (!obj.hasOwnProperty(key)) return undefined; // Implícita en el comportamiento de Array
const value = obj[key];
if (!value) return undefined;
if (!Array.isArray(value)) return undefined;
if (index > value.length) return undefined; // Implícita en el comportamiento de Array
if (value.length === 0) return undefined; // Implícita en el comportamiento de Array
return value[index];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment