Last active
April 9, 2018 01:09
-
-
Save mariogillazaro/d2ef830af71944ac0c484fdcae49d3ac to your computer and use it in GitHub Desktop.
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
// 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