Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions funcoes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Atividade 1 - Min e Max
function max(a, b) {
return a>b ? a :
a!=b ? b :
"Numeros são iguais"
}
function min(a, b) {
return a<b ? a :
a!=b ? b :
"Numeros são iguais"
}

// Atividade 2 - Modulo com Recursividade
function mod(num, modulo) {
if (num === 0) {
return true
}
if (num === 1) {
return false
}
if (num < 0) {
return mod(-num, modulo)
}
return mod(num - modulo, modulo)
}

// Atividade 3 - Contando Caracteres
function countChars(frase, c) {
let count = 0
for (let i = 0; i < frase.lenght; i++) {
if (c === frase[i]) {
count++
}
}
return count
}

console.log(max(13, 15))
console.log(min(13, 15))
console.log(mod(6, 3))
console.log(countChars("aaaa", "a"))


49 changes: 49 additions & 0 deletions intro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Atividade 1 - Triangulo
for (let hash = 2; hash <= 6; hash++){
hash_txt = "#"
console.log(hash_txt.repeat(hash))
}

console.log("\n".repeat(3))

// Atividade 2 - Xadrez
for (let row = 0; row < 8; row++){
if ((row % 2) == 0) {
hash_txt = "# "
console.log(hash_txt.repeat(4))
} else {
hash_txt = " #"
console.log(hash_txt.repeat(4))
}

}

console.log("\n".repeat(3))

// Atividade 3 - Palindromo
var palavra = "Ana"
palavra = palavra.toLowerCase()
if (palavra.split("").reverse().join("") === palavra) {
console.log("Eh um palindromo")
}
else {
console.log("Não eh u palindromo")
}

console.log("\n".repeat(3))

// Atividade 4 - Imprimir de 1 a 100
for (let i = 1; i <= 100; i++) {
if (i % 5 == 0 && i % 3 == 0) {
console.log("FizzBuzz")
}
else if (i % 3 == 0) {
console.log("Fizz")
}
else if (i % 5 == 0) {
console.log("Buzz")
}
else {
console.log(i)
}
}
98 changes: 98 additions & 0 deletions objetos&arrays.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Atividade 1 - Intervalos
function range(min, max, i) {
for (let j = min; j <= max; j+=2) {
console.log(j)
}
}

//Atividade 2 - Revertendo arrays
function reverseArray(array) {
const reversedArray = [];
for (let i = array.length - 1; i >= 0; i--) {
reversedArray.push(array[i]);
}
return reversedArray;
}

//Atividade 3 - Listas
function toList(array) {
if (array.length === 0) {
return null;
}

let list = {
value: array[0],
rest: null
};

let noAtual = list;
for (let i = 1; i < array.length; i++) {
const novoNo = {
value: array[i],
rest: null
};

noAtual.rest = novoNo;
noAtual = newNode;
}
return list;
}

// Atividade 4 - Deep Equals
function deepEquals(obj1, obj2) {
// Compara items
if (obj1 === obj2) {
return true
}

// Se algum for nulo ou não for objeto retorna falso
if (obj1 === null || obj2 === null || typeof obj1 !== 'object' || typeof obj2 !== 'object') {
return false
}

// Compara valores dentro de arrays do objeto
// Ex.: {a: [1, 2, 3]}
if (Array.isArray(obj1)) {
if (obj1.length !== obj2.length) {
return false
}

for (let i = 0; i < obj1.length; i++) {
if (!deepEquals(obj1[i], obj2[i])) {
return false
}
}
return true
}

// Compara valores dentro de objetos do objeto
// Ex.: {a: {b: 1}}
const keys1 = Object.keys(obj1);
const keys2 = Object.keys(obj2);
if (keys1.length !== keys2.length) {
return false
}

for (const key of keys1) {
if (!keys2.includes(key) || !deepEquals(obj1[key], obj2[key])) {
return false
}
}
return true
}

range(1, 10, 2)
console.log("\n".repeat(2))

console.log(reverseArray([1, 2, 3]))
console.log("\n".repeat(2))

const array = [1, 2, 3]
console.log(toList(array))
console.log("\n".repeat(2))

const obj1 = {a: 1, b: [2, 3, 4], c: {c: 2}};
const obj2 = {a: 1, b: [2, 3, 4], c: {c: 2}};
const obj3 = {a: 1, b: [2, 3, 4], c: {c: 3}};
console.log(deepEquals(obj1, obj2));
console.log(deepEquals(obj1, obj3));