Disciplina: TI - Desenvolvimento de Sistemas
Banca: Consulplan
Orgão: SEED-PR
- Fundamentos de ProgramaçãoAlgoritmosAnálise de Execução de Algoritmos
- Fundamentos de ProgramaçãoEstruturas de DadosEstrutura de Dados: Array
- Fundamentos de ProgramaçãoLógica de Programação
- WebJavaScript
Javascript possibilita, através da prototipação de funções, a agregação de funções complementares às já implementadas pela linguagem. A implementação apresentada é um exemplo de expansão das funcionalidades do tipo de dados Array. Com base neste contexto, exerça o rastreio do código-fonte Javascript a seguir, considerando a chamada “[1,2,3,5,8].funcaoDeProva()”.
1. Array.prototype.funcaoDeProva =
function(callback) {
2. 'use strict';
3. if (null === this || 'undefined' === typeof this) {
4. throw new TypeError('Vetor nulo ou não definido'
);
5. }
6. var t = Object(this), len = t.length >>> 0, k = len - 1,
value;
7. if (arguments.length >= 2) {
8. value = arguments[1];
9. } else {
10. while (k >= 0 && !(k in t)) {
11. k--;
12. }
13. if (k < 0) {
14. throw new TypeError('Vetor ');
15. }
16. value = t[k]%2 === 0 ? t[k] : 0;
17. k--;
18. }
19. for (; k >= 0; k--) {
20. if (k in t) {
21. value = value + (t[k]%2 === 0 ? t[k] : 0);
22. }
23. }
24. return value;
25. };
Assinale, a seguir, o valor retornado pela função.