Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function nameCase(str, LetterCase, invert) {
- let result = str.split('');
- if (LetterCase == 'upper') {
- result.forEach(function(element, ind, arr) {
- if (96 < element.charCodeAt(0) && element.charCodeAt(0) < 123) {
- arr[ind] = String.fromCharCode(element.charCodeAt(0) - 32);
- }
- });
- if (invert == true) {
- result[0] = String.fromCharCode(result[0].charCodeAt(0) + 32);
- }
- return result.join('')
- }
- if (LetterCase == 'lower') {
- result.forEach(function(element, ind, arr) {
- if (64 < element.charCodeAt(0) && element.charCodeAt(0) < 90) {
- arr[ind] = String.fromCharCode(element.charCodeAt(0) + 32);
- }
- });
- if (invert == true) {
- result[0] = String.fromCharCode(result[0].charCodeAt(0) - 32);
- }
- return result.join('')
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement