Skip to content

Commit

Permalink
Colocando exercicios Freecodecamp
Browse files Browse the repository at this point in the history
  • Loading branch information
CADU110 committed May 26, 2024
1 parent aa3b63d commit 903b98e
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 0 deletions.
32 changes: 32 additions & 0 deletions n1/palindromeCheck.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
function palindrome(str) {
let strSemEspacos = str.replace(/[^a-zA-Z0-9]/g, '').toLowerCase();
let tam = strSemEspacos.length
let m = Math.floor(tam/2);

let s;
let d;
if(tam%2==0){
s = m;
d = m-1;
}else{
s = m+1;
d = m-1;
}
let i = 0;
while(s < tam && d >= 0){
if(strSemEspacos[s]==strSemEspacos[d]){
i++;
}
s++;
d--;
}

if(i == m){
return true;
}else{
return false;
}
}


palindrome("eye");
50 changes: 50 additions & 0 deletions n2/romanNumeral.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
function convertToRoman(num) {
let final = '';
while(num > 0){
if(num >= 1000){
final +='M';
num -= 1000;
}else if(num >= 900){
final +='CM';
num -= 900;
}else if(num >= 500){
final +='D';
num -= 500;
}else if(num >= 400){
final +='CD';
num -= 400;
}else if(num >= 100){
final +='C';
num -= 100;
}else if(num >= 90){
final +='XC';
num -= 90;
}else if(num >= 50){
final +='L';
num -= 50;
}else if(num >= 40){
final +='XL';
num -= 40;
}else if(num >= 10){
final +='X';
num -= 10;
}else if(num >= 9){
final +='IX';
num -= 9;
}else if(num >= 5){
final +='V';
num -= 5;
}else if(num >= 4){
final +='IV';
num -= 1000;
}else if(num >= 1){
final +='I';
num -= 1;
}
}
return final;
}



convertToRoman(36);
7 changes: 7 additions & 0 deletions n3/telephoneValidador.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function telephoneCheck(str) {
let regex=/1?\s?((\d{3})|(\(\d{3}\)))[- ]?(\d{3})[- ]?(\d{4})/;

return regex.test(str) && str.match(regex)[0]===str;
}

telephoneCheck("555-555-5555");
21 changes: 21 additions & 0 deletions n4/caesarsCipher.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
function rot13(str) {
var encryptedString = str.split('').map(char => {
var regex = /[A-Z]/;
if (regex.test(char)) {
let asciiValue = char.charCodeAt(0);
let final;
if ((asciiValue - 13)-65 < 0) {
final =(asciiValue-65)+78;
} else {
final = asciiValue - 13;
}
return String.fromCharCode(final);
}
return char;
}).join('');
console.log(encryptedString);

return encryptedString;
}

rot13("SERR PBQR PNZC");

0 comments on commit 903b98e

Please sign in to comment.