--- id: 56533eb9ac21ba0edf2244ca title: Using Objects for Lookups challengeType: 1 videoUrl: '' localeTitle: Uso de objetos para búsquedas --- ## Description
Los objetos pueden considerarse como un almacenamiento de clave / valor, como un diccionario. Si tiene datos tabulares, puede usar un objeto para "buscar" valores en lugar de una instrucción switch o una cadena if/else . Esto es más útil cuando sabe que sus datos de entrada están limitados a un cierto rango. Aquí hay un ejemplo de una búsqueda de alfabeto inversa simple:
var alfa = {
1: "Z",
2: "Y",
3: "X",
4: "W",
...
24: "C",
25: "B",
26: "A"
};
alfa [2]; // "Y"
alfa [24]; // "C"

valor de var = 2;
alfa [valor]; // "Y"
## Instructions
Convertir la instrucción switch en un objeto llamado lookup . Úselo para buscar val y asignar la cadena asociada a la variable de result .
## Tests
```yml tests: - text: phoneticLookup("alpha") debería ser igual a "Adams" testString: 'assert(phoneticLookup("alpha") === "Adams", "phoneticLookup("alpha") should equal "Adams"");' - text: phoneticLookup("bravo") debería ser igual a "Boston" testString: 'assert(phoneticLookup("bravo") === "Boston", "phoneticLookup("bravo") should equal "Boston"");' - text: phoneticLookup("charlie") debe ser igual a "Chicago" testString: 'assert(phoneticLookup("charlie") === "Chicago", "phoneticLookup("charlie") should equal "Chicago"");' - text: phoneticLookup("delta") debe ser igual a "Denver" testString: 'assert(phoneticLookup("delta") === "Denver", "phoneticLookup("delta") should equal "Denver"");' - text: phoneticLookup("echo") debe ser igual a "Easy" testString: 'assert(phoneticLookup("echo") === "Easy", "phoneticLookup("echo") should equal "Easy"");' - text: phoneticLookup("foxtrot") debe ser igual a "Frank" testString: 'assert(phoneticLookup("foxtrot") === "Frank", "phoneticLookup("foxtrot") should equal "Frank"");' - text: phoneticLookup("") debe ser igual a undefined testString: 'assert(typeof phoneticLookup("") === "undefined", "phoneticLookup("") should equal undefined");' - text: No debes modificar la declaración de return . testString: 'assert(code.match(/return\sresult;/), "You should not modify the return statement");' - text: 'No debe usar case , switch , o if declaraciones' testString: 'assert(!/case|switch|if/g.test(code.replace(/([/]{2}.*)|([/][*][^/*]*[*][/])/g,"")), "You should not use case, switch, or if statements"); ' ```
## Challenge Seed
```js // Setup function phoneticLookup(val) { var result = ""; // Only change code below this line switch(val) { case "alpha": result = "Adams"; break; case "bravo": result = "Boston"; break; case "charlie": result = "Chicago"; break; case "delta": result = "Denver"; break; case "echo": result = "Easy"; break; case "foxtrot": result = "Frank"; } // Only change code above this line return result; } // Change this value to test phoneticLookup("charlie"); ```
## Solution
```js // solution required ```