Advertisement
Threed90

NamingConvence

Jan 25th, 2022
658
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.  
  3.   let library = {
  4.     'Camel Case': function (input) {
  5.       return input.map((e, i) => {
  6.         if (i === 0) {
  7.           return e.toLowerCase();
  8.         } else {
  9.           let result = e[0].toUpperCase() + e.slice(1).toLowerCase();
  10.  
  11.           return result;
  12.         }
  13.       }).join('');
  14.  
  15.     },
  16.     'Pascal Case': function (input) {
  17.       return input.map(e => e[0].toUpperCase() + e.slice(1).toLowerCase()).join('');
  18.     }
  19.   };
  20.  
  21.   let textTokens = document.getElementById('text').value.split(' ');
  22.   let namingCase = document.getElementById('naming-convention').value;
  23.  
  24.   if(library[namingCase]){
  25.     document.getElementById('result').textContent = library[namingCase](textTokens);
  26.   } else {
  27.     document.getElementById('result').textContent = 'Error!';
  28.   }
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement