diff --git a/ex1.js b/ex1.js new file mode 100644 index 0000000..c982a59 --- /dev/null +++ b/ex1.js @@ -0,0 +1,8 @@ +let num = parseInt(prompt("Digite o numero de linhas")) + +let htag = "#" + +for(let i = 0; i < num; i++){ + console.log(htag) + htag += "#" +} diff --git a/ex10.js b/ex10.js new file mode 100644 index 0000000..3b99996 --- /dev/null +++ b/ex10.js @@ -0,0 +1,37 @@ +var list = { + value: 1, + rest: { + value: 2, + rest: { + value: 3, + rest: null + } + } +}; + +function toList(array){ + let list = {value: 0, rest: null} + for(let i =0; i < array.length - 1; i++){ + tmp = list + while(tmp.rest != null){ + tmp = tmp.rest + } + tmp.value = array[i] + tmp.rest = {value: 0, rest: null} + } + return list +} + +function printElem(list){ + while(list != null){ + console.log(list.value) + list = list.rest + } +} + +array = [2, 6, 3, 9, 0, 11, 20, 7] + +x = toList(array) + +console.log(x) +printElem(x) \ No newline at end of file diff --git a/ex11.js b/ex11.js new file mode 100644 index 0000000..c081bba --- /dev/null +++ b/ex11.js @@ -0,0 +1,30 @@ +function deepEquals(obj1, obj2){ + let key1 = Object.keys(obj1); + let key2 = Object.keys(obj2); + + if(key1.length != key2.length){ + return false + } + for(let i = 0; i < key1.length; i++){ + if((key1[i] in obj2) == false){ + return false; + } + } + return true; +} + +l1 = { + value: 1, + item: 2, + index: 3, + teste: 4 +} + +l2 = { + value: 3, + item: 0, + index: 5, + teste: 9 +} + +console.log(deepEquals(l1, l2)) \ No newline at end of file diff --git a/ex12.js b/ex12.js new file mode 100644 index 0000000..23758e2 --- /dev/null +++ b/ex12.js @@ -0,0 +1,48 @@ +function mod(num){ + if(num < 0){ + return num * -1; + } + return num; +} +/* +1 Ordena Crescente +-1 Ordena Decrescente +2 Ordena Crescente Pares +-2 Ordena Decrescente Pares +3 Ordena Crescente IMpares +-3 Ordena Decrescente Imapres +*/ +function ordena(array, crit){ + let finalArray = []; + for(let i = 0; i < array.length; i++){ + for(let j = i; j < array.length; j ++){ + tmp = array[j]; + if(crit > 0){ + if(array[i] > tmp){ + array[j] = array[i]; + array[i] = tmp; + } + }else { + if(array[i] < tmp){ + array[j] = array[i]; + array[i] = tmp; + } + } + } + } + for(let i =0; i 87){ + x -= 26; + } + if(str.charAt(i).toLowerCase() != str.charAt(i).toUpperCase()) + finalStr += String.fromCharCode(x + 3); + else{ + finalStr += str.charAt(i); + } + } + return finalStr; +} + +console.log(cripto("mlzzko zzzm")); \ No newline at end of file diff --git a/ex14.js b/ex14.js new file mode 100644 index 0000000..e6c7a7a --- /dev/null +++ b/ex14.js @@ -0,0 +1,24 @@ +function impar(num){ + if(num % 2 == 1){ + return true; + } + return false; +} +function primo(num){ + for(let i = 2 ;i < num; i++){ + if(num % i == 0){ + return false; + } + } + return true; +} + +function veri(num, func){ + return func(num); +} + +console.log(veri(15, primo)) +console.log(veri(7, primo)) + +console.log(veri(15, impar)) +console.log(veri(8, impar)) \ No newline at end of file diff --git a/ex2.js b/ex2.js new file mode 100644 index 0000000..a3b7ef5 --- /dev/null +++ b/ex2.js @@ -0,0 +1,10 @@ +let num = parseInt(prompt("Digite o numero de linhas")) + +let htag = "# # # #" + +for(let i = 0; i < num; i++){ + if(i % 2 == 0) + console.log(htag); + else + console.log(" " + htag); +} \ No newline at end of file diff --git a/ex3.js b/ex3.js new file mode 100644 index 0000000..75bab71 --- /dev/null +++ b/ex3.js @@ -0,0 +1,19 @@ +let texto = prompt("Digite uma palavra para ver se é palindromo") + +function palindromo(text){ + let pali = true; + let num = text.length + for(let i = 0; i< num; i ++){ + if(text[i] != text[num - 1 -i]){ + pali = false + } + } + return pali +} + +if(palindromo(texto)){ + console.log("É um palindromo") +} +else { + console.log("Não é um palindromo") +} \ No newline at end of file diff --git a/ex4.js b/ex4.js new file mode 100644 index 0000000..651d737 --- /dev/null +++ b/ex4.js @@ -0,0 +1,14 @@ +for(let i = 1; i <= 100; i++){ + if(i % 3 == 0 && i % 5 == 0){ + console.log("FiizBuzz") + } + else if(i % 3 == 0){ + console.log("Fiiz") + } + else if(i % 5 == 0){ + console.log("Buzz") + } + else{ + console.log(i) + } +} \ No newline at end of file diff --git a/ex5.js b/ex5.js new file mode 100644 index 0000000..abc2b52 --- /dev/null +++ b/ex5.js @@ -0,0 +1,35 @@ +function max(a, b){ + if(a == b){ + return null + }else if(a > b){ + return a + }else { + return b + } +} + +function min(a, b){ + if(a == b){ + return null + }else if(a < b){ + return a + }else { + return b + } +} + +function testa(x, y){ + if(max(x, y) != null){ + console.log("O maior numero é " + max(x, y) + " Menor numero é ", min(x, y)) + }else { + console.log("Os numeros são iguais") + } +} + +testa(3, 8) +testa(340, 276) +testa(20, 20) + + + + diff --git a/ex6.js b/ex6.js new file mode 100644 index 0000000..3f8817f --- /dev/null +++ b/ex6.js @@ -0,0 +1,42 @@ +function mod2(num){ + if(num > 1){ + return mod2(num -2) + } + else if(num == 1){ + return false + }else{ + return true + } +} + +function mod(num, mod){ + if(num > 1){ + return mod2(num - mod) + } + else if(num == 1){ + return false + }else{ + return true + } +} +let num = parseInt(prompt("Digite um numero para ver se é divisivel por dois")) + +if(mod2(num) == true){ + console.log("É divisivel por dois") +}else{ + console.log("Não é divisivel por dois") +} + +num = parseInt(prompt("Digite o numero para ver se é divisivel")) +let m = parseInt(prompt("Digite o modulo")) + +if(mod(num, m) == true){ + console.log("É divisivel") +}else{ + console.log("Não é divisivel") +} + + + + + diff --git a/ex7.js b/ex7.js new file mode 100644 index 0000000..c54047b --- /dev/null +++ b/ex7.js @@ -0,0 +1,14 @@ +let text = prompt("Digite uma palavra/frase") +let abc = prompt("Digite um caracter") + +function countChars(str, ch){ + let count = 0 + for(let i = 0; i < str.length; i++){ + if(str[i] == ch){ + count ++ + } + } + return count +} + +console.log(countChars(text, abc)) diff --git a/ex8.js b/ex8.js new file mode 100644 index 0000000..e04a2b6 --- /dev/null +++ b/ex8.js @@ -0,0 +1,19 @@ +let min = parseInt(prompt("Digite o menor numero")) +let max = parseInt(prompt("Digite o maior")) +let num = parseInt(prompt("Digite o intervalo")) + +function range(min, max, i){ + let array = [] + for(let j = min; j <= max; j+=i){ + array.push(j) + } + return array +} + +if(min > max){ + let tmp = min + min = max + max = tmp +} + +console.log(range(min, max, num)) diff --git a/ex9.js b/ex9.js new file mode 100644 index 0000000..33b44f5 --- /dev/null +++ b/ex9.js @@ -0,0 +1,12 @@ +function reverseArray(array){ + let reverse = [] + + for(let i = array.length - 1; i >= 0; i--){ + reverse.push(array[i]) + } + return reverse +} + +array = [1, 4, 7, 2, 9, 0] + +console.log(reverseArray(array)) \ No newline at end of file