diff --git a/n1/palindromeCheck.js b/n1/palindromeCheck.js new file mode 100644 index 0000000..646033b --- /dev/null +++ b/n1/palindromeCheck.js @@ -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"); diff --git a/n2/romanNumeral.js b/n2/romanNumeral.js new file mode 100644 index 0000000..c1b9869 --- /dev/null +++ b/n2/romanNumeral.js @@ -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); diff --git a/n3/telephoneValidador.js b/n3/telephoneValidador.js new file mode 100644 index 0000000..b2430cb --- /dev/null +++ b/n3/telephoneValidador.js @@ -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"); diff --git a/n4/caesarsCipher.js b/n4/caesarsCipher.js new file mode 100644 index 0000000..cd5dff3 --- /dev/null +++ b/n4/caesarsCipher.js @@ -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");