Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function transliterate(text) {
- const transliterationMap = {
- // lower case
- 'a' : 'а',
- 'b' : 'б',
- 'c' : 'к',
- 'd' : 'д',
- 'e' : 'е',
- 'f' : 'ф',
- 'g' : 'г',
- 'h' : 'х',
- 'i' : 'и',
- 'j' : 'дж',
- 'k' : 'к',
- 'l' : 'л',
- 'm' : 'м',
- 'n' : 'н',
- 'o' : 'о',
- 'p' : 'п',
- 'q' : 'к',
- 'r' : 'р',
- 's' : 'с',
- 't' : 'т',
- 'u': ['у', 'ю'],
- 'v' : 'в',
- 'w' : 'в',
- 'x' : 'екс',
- 'y' : 'и',
- 'z' : 'з',
- // upper case
- 'A' : 'А',
- 'B' : 'Б',
- 'C' : 'К',
- 'D' : 'Д',
- 'E' : 'Е',
- 'F' : 'Ф',
- 'G' : 'Г',
- 'H' : 'Х',
- 'I' : 'И',
- 'J' : 'ДЖ',
- 'K' : 'К',
- 'L' : 'Л',
- 'M' : 'М',
- 'N' : 'Н',
- 'O' : 'О',
- 'P' : 'П',
- 'Q' : 'К',
- 'R' : 'Р',
- 'S' : 'С',
- 'T' : 'Т',
- 'U': ['У', 'Ю'],
- 'V' : 'В',
- 'W' : 'В',
- 'X' : 'ЕКС',
- 'Y' : 'И',
- 'Z' : 'З',
- };
- text = text.replace(/ия\b/g, "ia")
- .replace(/Ия\b/g, "Ia")
- .replace(/иЯ\b/g, "iA")
- .replace(/ИЯ\b/g, "IA");
- const transliteratedText = text.split('').map(letter => {
- if (transliterationMap[letter]) {
- if (Array.isArray(transliterationMap[letter])) {
- return transliterationMap[letter].join('/');
- } else {
- return transliterationMap[letter];
- }
- } else {
- return letter;
- }
- }).join('');
- return transliteratedText.replace(/\//g, ' / ');
- }
- // Event listeners
- buttonCalculate.onclick = (e) => {
- e.preventDefault();
- separateWords();
- modal.style.display = "block";
- modal.style.opacity = "1";
- };
- buttonClean.onclick = (e) => {
- e.preventDefault();
- cleanAll();
- };
- buttonFilter.onclick = (e) => {
- e.preventDefault();
- displayResults();
- };
- const cleanAll = () => {
- result.innerHTML = "";
- inputName.value = "";
- errorDiv.innerText = "";
- modal.style.display = "none";
- filterNumberInput.value = "";
- allResults = [];
- };
- const separateWords = () => {
- const words = inputName.value.toLowerCase().split(' ');
- if (words.length === 0 || inputName.value === "") {
- errorDiv.innerText = "Please, write your name.";
- return;
- }
- allResults = [];
- words.forEach(word => {
- if (word !== "") {
- calculateWordNumerology(word);
- }
- });
- displayResults();
- };
- const calculateWordNumerology = (word) => {
- let sum = word.split('').map(letter => lettersToNumbers[letter] || 0).reduce((acc, curr) => acc + curr, 0);
- let destinyNumber = reduceNumber(sum);
- allResults.push({ word, destinyNumber });
- };
- const calculateNumerology = (word) => {
- let sum = word.split('').map(letter => lettersToNumbers[letter.toLowerCase()] || 0).reduce((acc, curr) => acc + curr, 0);
- return reduceNumber(sum);
- };
- const reduceNumber = (number) => {
- while (number > 9) {
- number = number.toString().split('').reduce((acc, digit) => acc + parseInt(digit, 10), 0);
- }
- return number;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement