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"
lookup
. Úselo para buscar val
y asignar la cadena asociada a la variable de result
. 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"); '
```