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
91 changes: 91 additions & 0 deletions changeString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
var minha_frase = "uma frase toda minuscula para testes";
var minha_frase2 = "OUTRA FRASE SO QUE TODA MAIUSCULA PARA TESTES";

function upper(array, char){

var tmp = array;
if(array[0] == char){
tmp = array[0].toUpperCase() + array.slice(1);
}else{
for(i = 1; i < array.length; i++){
if(array[i] == char){
tmp = array.slice(0, i) + array[i].toUpperCase() + array.slice(++i);
break;
}
}
}
return tmp;
}

function lower(array, char){

var tmp = array;
if(array[0] == char){
tmp = array[0].toLowerCase() + array.slice(1);
}else{
for(i = 1; i < array.length; i++){
if(array[i] == char){
tmp = array.slice(0, i) + array[i].toLowerCase() + array.slice(++i);
break;
}
}
}
return tmp;
}

function upperVogais(old){

var vogais = "aeiou";
var novo = old;
for(j = 0; j < vogais.length; j++){
for(i = 0; i < old.length; i++){
novo = upper(novo, vogais[j]);
}
}
return novo;
}

function lowerVogais(old){

var vogais = "AEIOU";
var novo = old;
for(j = 0; j < vogais.length; j++){
for(i = 0; i < old.length; i++){
novo = lower(novo, vogais[j]);
}
}
return novo;
}

function upperConsoantes(old){

var consoantes = "bcdfghjklmnpqrstvxyz";
var novo = old;
for(j = 0; j < consoantes.length; j++){
for(i = 0; i < old.length; i++){
novo = upper(novo, consoantes[j]);
}
}
return novo;
}

function lowerConsoantes(old){

var consoantes = "BCDFGHJKLMNPQRSTVXYZ";
var novo = old;
for(j = 0; j < consoantes.length; j++){
for(i = 0; i < old.length; i++){
novo = lower(novo, consoantes[j]);
}
}
return novo;
}

function changeString(frase, condicao){
return condicao(frase);
}

console.log("Vogais maiusculas - " + changeString(minha_frase, upperVogais));
console.log("Vogais minusculas - " + changeString(minha_frase2, lowerVogais) + "\n");
console.log("Consoantes maiusculas - " + changeString(minha_frase, upperConsoantes));
console.log("Consoantes minusculas - " + changeString(minha_frase2, lowerConsoantes));
15 changes: 15 additions & 0 deletions countChars.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
var palavra = prompt("Digite uma palavra ou frase - ")
var char = prompt("Digite um caractere - ");

function countChars(frase, c){

var quant = 0;
for(i = 0; i < frase.length; i++){
if(frase[i] == c){
quant++;
}
}
return quant;
}

console.log("Seu caractere apareceu " + countChars(palavra, char) + " vezes");
29 changes: 29 additions & 0 deletions criptografia.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
var minha_frase = "Uma frase para fim de testes muahahahahha"
var td = "abcdefghijklmnopqrstuvwxyz";

function cifraCesar(frase, key){

var novo = [];
var aux;
var tmp = frase.toLowerCase();

for(i = 0; i < tmp.length; i++){
for(j = 0; j < td.length; j++){
if(tmp[i] == td[j]){
aux = j + key;
if(aux >= td.length){
aux = aux - td.length;
}
novo[i] = td[aux];
break;
}
}
}
return novo.join("");
}

function criptografia(frase, criterio){
return criterio(frase, 3);
}

console.log(criptografia(minha_frase, cifraCesar));
30 changes: 30 additions & 0 deletions deepEquals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var meu_obj1 = {
num: 1,
nome: "eu",
haha: null
}
var meu_obj2 = {
num: 2,
nome: "voce",
haha: null
//jaja: null
}

function deepEquals(obj1, obj2){

var tmp1 = [];
for (var prop in obj1){
tmp1.push(prop);
}
var tmp2 = [];
for (var prop in obj2){
tmp2.push(prop);
}
if(JSON.stringify(tmp1) == JSON.stringify(tmp2)){
return true;
}else{
return false;
}
}

console.log("Os objetos sao iguais? - " + deepEquals(meu_obj1, meu_obj2));
43 changes: 43 additions & 0 deletions intervalos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
var num1 = 14;
var num2 = 132;
var variacao = 4;

function range(min, max){

var aux = 0;
if(min > max){
aux = min;
min = max;
max = aux;
}

var array = [];
aux = max - min;
for(i = 0; i <= aux ; i++){
array[i] = min++;
}
return array;
}

function range2(min, max, i){

var aux = 0;
if(min > max){

aux = min;
min = max;
max = aux;
}

var array = [];
for(j = 0; j <= max ; j++){
array[j] = min;
min += i;
if(min > max)
{ break; }
}
return array;
}

console.log(range(num1, num2));
console.log(range2(num1, num2, variacao));
44 changes: 44 additions & 0 deletions matriz.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
function criaMatriz(linhas, colunas, funcao){

var matriz = [];
for(i = 0; i < linhas; i++){
var tmp = [];
for(j = 0; j < colunas; j++){
tmp[j] = funcao((i + 1), (j + 1));
}
matriz[i] = tmp;
}

return matriz;
}

function funcao1(i, j){
return i + j;
}

function funcao2(i, j){
return i * j;
}

function funcao3(i, j){
return i == j ? 1 : 0;
}

function funcao4(i, j){
return i**2/(j+1);
}

function funcao5(i, j){
return i > j ? 1 : (i < j ? 5 : 0);
}

console.log("Funcao 1");
console.log(criaMatriz(5, 5, funcao1));
console.log("Funcao 2");
console.log(criaMatriz(5, 5, funcao2));
console.log("Funcao 3");
console.log(criaMatriz(5, 5, funcao3));
console.log("Funcao 4");
console.log(criaMatriz(5, 5, funcao4));
console.log("Funcao 5");
console.log(criaMatriz(5, 5, funcao5));
21 changes: 21 additions & 0 deletions maxEmin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
var num1 = prompt("Digite o primeiro valor - ");
var num2 = prompt("Digite o segundo valor - ");

function min(a, b){
if(a < b){
return a;
}else{
return b;
}
}

function max(a, b){
if(a < b){
return b;
}else{
return a;
}
}

console.log("min - "+ min(num1, num2));
console.log("max - "+ max(num1, num2));
47 changes: 47 additions & 0 deletions ordena.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var meu_array = [3, 5, 1, 10, 4, 2, 6];

//bubble sort
function ordena(array, condicao){

for(i = 0; i < array.length; i++){
for(j = 0; j < array.length - 1; j++){
if(condicao(array[j], array[j + 1])){
var tmp = array[j];
array[j] = array[j + 1];
array[j + 1] = tmp;
}
}
}
return array;
}

function par_impar(array, aux){
var novo = [];
var j = 0;
//aux = true - numeros pares
//aux = false - numeros impares
for(i = 0; i < array.length; i++){
if(((array[i] % 2) == 0 && aux) || ((array[i] % 2) != 0 && !aux) ){
novo[j] = array[i];
j++;
}
}
return novo;
}
//crescente
console.log(ordena(meu_array, function(a, b){
return (a > b);
}));
//decrescente
console.log(ordena(meu_array, function(a, b){
return (a < b);
}))

//impar crescente
console.log(ordena(par_impar(meu_array, false), function(a, b){
return (a > b);
}));
//par decrescente
console.log(ordena(par_impar(meu_array, true), function(a, b){
return (a < b);
}));
19 changes: 19 additions & 0 deletions palindromo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
var palavra = prompt("Digite sua palavra - ");

var tam = palavra.length - 1;
var checa = true;

for(i = 0; i < palavra.length; i++){
if(palavra[i] == palavra[tam]){
tam--;
}else{
checa = false;
break;
}
}

if(checa == true){
console.log("É um palíndromo! ");
}else{
console.log("Não é um palíndromo...")
}
23 changes: 23 additions & 0 deletions programaDiferente.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var c = 0;
var msg = "";

for(i = 1; i <= 100; i++){

var a = i.toString();
for(j = 0; j < a.length; j++){
c += a[j];
}

if((c % 3) == 0){
msg += "Fizz"
}

if ((c % 5) == 0){
msg += "Buzz";
}

console.log(i + msg);

c = 0;
msg = " ";
}
Loading