Last active
August 29, 2015 13:56
-
-
Save bradoyler/9156470 to your computer and use it in GitHub Desktop.
Lesson #2: string manipulation and counting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//reverse characters in string | |
console.log('test string'.split('').reverse().join('')); // output: gnirts tset | |
// count characters in a string | |
function Char_Counts(str1) { | |
var uchars = {}; | |
str1.replace(/\S/g, function(l){ | |
uchars[l] = (isNaN(uchars[l]) ? 1 : uchars[l] + 1); | |
}); | |
return uchars; | |
} | |
console.log(Char_Counts("test string")); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment