Advertisement
CR7CR7

intoCamelCase

Dec 25th, 2023
1,017
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const convertCamel = function (varNames) {
  2.   const initial = varNames.trim().toLowerCase();
  3.   const converted = initial.slice(initial.indexOf('_')).replace('_', '');
  4.   const capitalize = converted.replace(
  5.     converted[0],
  6.     converted[0].toUpperCase()
  7.   );
  8.  
  9.   const camaled = initial.slice(0, initial.indexOf('_')) + capitalize;
  10.   const ticks = '✅'.repeat(converted.length); // Add green ticks based on the length of the converted variable name
  11.   return `${camaled}${ticks}`;
  12. };
  13.  
  14. console.log(convertCamel('underscore_case'));
  15. console.log(convertCamel('first_name'));
  16. console.log(convertCamel('Some_Variable'));
  17. console.log(convertCamel(' calculate_AGE'));
  18. console.log(convertCamel('delayed_departure'));
  19.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement