Advertisement
Guest User

Untitled

a guest
Mar 26th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. function nameCase(str, LetterCase, invert) {
  2. let result = str.split('');
  3. if (LetterCase == 'upper') {
  4. result.forEach(function(element, ind, arr) {
  5. if (96 < element.charCodeAt(0) && element.charCodeAt(0) < 123) {
  6. arr[ind] = String.fromCharCode(element.charCodeAt(0) - 32);
  7. }
  8. });
  9. if (invert == true) {
  10. result[0] = String.fromCharCode(result[0].charCodeAt(0) + 32);
  11. }
  12. return result.join('')
  13. }
  14. if (LetterCase == 'lower') {
  15. result.forEach(function(element, ind, arr) {
  16. if (64 < element.charCodeAt(0) && element.charCodeAt(0) < 90) {
  17. arr[ind] = String.fromCharCode(element.charCodeAt(0) + 32);
  18. }
  19. });
  20. if (invert == true) {
  21. result[0] = String.fromCharCode(result[0].charCodeAt(0) - 32);
  22. }
  23. return result.join('')
  24. }
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement