This file contains hidden or 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
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ; FizzBuzz - Testes | |
| ; Diullei Gomes | |
| ; [email protected] | |
| ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (ns FizzBuzz.core-test | |
| (:use [FizzBuzz.core] :reload-all) | |
| (:use [clojure.test])) |
This file contains hidden or 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
| // exemplo de código... | |
| namespace EasySyntax.TestProject | |
| { | |
| public class MyGramar : Grammar | |
| { | |
| public MyGramar() | |
| { | |
| Nonterminal("digt", | |
| Or("0", "1", "2", "3", "4", "5", "6", "7", "8", "9")); |
This file contains hidden or 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
| function strFormat() { | |
| // Note que o objeto arguments não é um array e por isso vamos criar um | |
| // array com os argumentos passados para a função. Assim fica mais fácil | |
| // utilizar os métodos nativos do do array. | |
| var list = Array.prototype.slice.call(arguments); | |
| // Como esta função será introduzida via protótipo no objeto String do | |
| // JavaScript iremos armazenar o valor da string a ser manipulada recuperando | |
| // o próprio contexto desta função | |
| var str = this; |
This file contains hidden or 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
| function fatorial(n) { | |
| return (!(n>1))? 1 : fatorial(n-1)*n; | |
| } | |
| [1,2,3,4,5].map(fatorial); |
This file contains hidden or 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
| [1,2,3,4,5].map(function(n) { | |
| return (!(n>1))? 1 : /* o que colocar aqui para referenciar novamente esta função?! */(n-1)*n; | |
| }); |
This file contains hidden or 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
| [1,2,3,4,5].map(function(n) { | |
| return (!(n>1))? 1 : arguments.callee(n-1)*n; | |
| }); |
This file contains hidden or 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
| [1,2,3,4,5].map(function fatorial(n) { | |
| return (!(n>1))? 1 : fatorial(n-1)*n; | |
| }); |
This file contains hidden or 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
| // Crio um objeto com o campo _num. | |
| function MyObj(){ | |
| this._num = 0; | |
| } | |
| // Adicionamos uma função recursiva para incrementar o valor de _num até que ele seja maior ou igual a 10. | |
| MyObj.prototype.Inc = function(){ | |
| console.log(this._num); | |
| this._num++; | |
| if(this._num >= 10) |
This file contains hidden or 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
| MyObj.prototype.Inc = function $Inc(){ | |
| console.log(this._num); | |
| this._num++; | |
| if(this._num >= 10) | |
| return; | |
| // chamada recursiva da mesma função. Se chamássemos simplesmente utilizando arguments.callee() | |
| // causaríamos um estouro de pilha por que nunca teríamos o estado do campo _num preservado, | |
| // já que o contexto da função estaria sempre mudando a cada chamada. Para manter este contexto | |
| // ativo estamos utilizando a função apply do objeto Function qye nos permite passar o contexto para o qual | |
| // queremos que a função execute. O mesmo ocorreria caso quiséssemos utilizar o alias $Inc. Escreveríamos |
This file contains hidden or 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
| function minhaFuncao(){ | |
| console.log(arguments.length); | |
| } | |
| minhaFuncao(0, 1, 2, 3, 4, 5, 6) | |
| //=> 7 |