diff --git a/conceitos_basicos/contador.js b/conceitos_basicos/contador.js new file mode 100644 index 0000000..b1abd84 --- /dev/null +++ b/conceitos_basicos/contador.js @@ -0,0 +1,7 @@ +for (i = 1; i< 100; i++) +{ + if (i/3 == parseInt(i/3) && i/5 == parseInt(i/5)) console.log("FizzBuzz"); + else if (i/3 == parseInt(i/3)) console.log("Fizz"); + else if (i/5 == parseInt(i/5)) console.log("Buzz"); + else console.log(i); +} \ No newline at end of file diff --git a/conceitos_basicos/palindromo.js b/conceitos_basicos/palindromo.js new file mode 100644 index 0000000..74da549 --- /dev/null +++ b/conceitos_basicos/palindromo.js @@ -0,0 +1,19 @@ +let str = "arara"; + +// cria vetor a partir da string dada pelo usuario -> split +let rev = str.split(""); +// inverte a ordem dos elementos do vetor-> reverse +rev = rev.reverse(); +// junto elementos do vetor em uma string -> join +rev = rev.join(""); + +for(i=0, test = true; i < str.length;i++) +{ + if (str[i] != rev[i]) + { + test = false; + console.log("\"" + str +"\""+" não é um palíndromo"); + break; + } +} +if (test == true) console.log("\"" + str+"\""+" é um palíndromo"); \ No newline at end of file diff --git a/conceitos_basicos/triangulo.js b/conceitos_basicos/triangulo.js new file mode 100644 index 0000000..84b4ea0 --- /dev/null +++ b/conceitos_basicos/triangulo.js @@ -0,0 +1,6 @@ +var n_linhas = prompt ("Digite a quantidade de linhas"); +for (i = 1; i <=n_linhas; i++) +{ + for( j=0, hash="#" ; j b ) + { + inter = a - b; + max = a; + min = b; + } + else + { + inter = b - a; + max = b; + min = a; + } + + if (inter == 0) return NaN; + return min + 1; +} +function max (a, b) +{ + let max; + let min; + let inter = 0; + if ( a > b ) + { + inter = a - b; + max = a; + min = b; + } + else + { + inter = b - a; + max = b; + min = a; + } + + if (inter == 0) return NaN; + return max - 1; +} +let x = min(2,6); +let y = max(2,6); +console.log("min:", x +"\nmax:", y); \ No newline at end of file diff --git a/funcao/mod.js b/funcao/mod.js new file mode 100644 index 0000000..edf6060 --- /dev/null +++ b/funcao/mod.js @@ -0,0 +1,6 @@ +function mod (num,mod) +{ + if (num/mod == parseInt(num/mod)) return true; + else return false; +} +console.log(mod(8,2)); \ No newline at end of file diff --git a/funcao/mod2.js b/funcao/mod2.js new file mode 100644 index 0000000..97ca556 --- /dev/null +++ b/funcao/mod2.js @@ -0,0 +1,6 @@ +function mod2 (number) +{ + if (number/2 == parseInt(number/2)) return true; + else return false; +} +console.log(mod2(8)); \ No newline at end of file diff --git a/objetos_arrays/deep_equal.js b/objetos_arrays/deep_equal.js new file mode 100644 index 0000000..d43c87a --- /dev/null +++ b/objetos_arrays/deep_equal.js @@ -0,0 +1,20 @@ +function deepEquals(obj1,obj2) +{ + var keys1 = []; + for(var key1 in obj1) keys1.push(key1); + console.log(keys1) + + var keys2 = []; + for(var key2 in obj2) keys2.push(key2); + console.log(keys2) + + if (JSON.stringify(keys1) === JSON.stringify(keys2)) return true; + else return false; +} + +var a = {"letter":"A","num":42}; +var b = {"letter":"B","num":73}; +var clone = {"letter":"A","num":42}; + +console.log(deepEquals(a,b)); +console.log(deepEquals(a,clone)); \ No newline at end of file diff --git a/objetos_arrays/intervalos.js b/objetos_arrays/intervalos.js new file mode 100644 index 0000000..c1a8eaf --- /dev/null +++ b/objetos_arrays/intervalos.js @@ -0,0 +1,11 @@ +function range(min,max) +{ + let inter= max - min; + const vet = []; + for (i = 1; i < inter; i++) + { + vet.push(min+i); + } + return vet; +} +console.log(range(2,8)); \ No newline at end of file diff --git a/objetos_arrays/list.js b/objetos_arrays/list.js new file mode 100644 index 0000000..627c013 --- /dev/null +++ b/objetos_arrays/list.js @@ -0,0 +1,32 @@ +function toList(array, len) +{ + var list = { + value: 0, + rest: null, + }; + for (i=0;i