Skip to content

Instantly share code, notes, and snippets.

@kostikovmu
kostikovmu / telephoneCheck
Created April 2, 2022 11:22
us phone validator
function telephoneCheck(str) {
const phoneRegxep = /^((\(\d{3}\))|((1\s|1)\(\d{3}\))|(\d{3})|(1\s\d{3}))(\s|-|)(\d{3})(\s|-)(\d{4})/
const d10 = /^\d{10}$/
return phoneRegxep.test(str) || d10.test(str);
}
// phone formats
// 555-555-5555
@kostikovmu
kostikovmu / rot13Decode
Last active April 1, 2022 10:16
ROT13 cipher ( ROT13 шифр )
function rot13Decode(str) {
return [...str].map( el => {
const code = el.charCodeAt(0)
const newCode = code > 77 && code < 91 ? + code - 13 :
code > 64 && code < 78 ? code + 13 : code
return String.fromCharCode(newCode)
}).join('');
}
@kostikovmu
kostikovmu / convertToRoman
Last active April 1, 2022 10:15
convert to roman js ( конвектор в римские числа )
function convertToRoman(num) {
const arr = num.toString().split('').map( el => +el).reverse();
let res = ''
const v10 = [
'I', 'X', 'C', 'M'
]
const v5 = [
'V', 'L' , 'D'
]
arr.forEach( (el, i) => {