Tech Kraft

Documentum, AWS, Java, Ruby on Rails, Linux, Windows, App Servers


Javascript: String Manipulations

Check String for Palindrome:

function palindrome(str) {
var result = true;
 var newStr='';
 
 for(var i=0;i<str.length;i++){
 if(/[a-zA-Z0-9]/gi.test(str.charAt(i))){
 newStr+= str.charAt(i);
 }
 }
 
 var revStr='';
for(var j=0;j<newStr.length; j++){
 if(newStr.charAt(j).toLowerCase() != newStr.charAt(newStr.length-j-1).toLowerCase()){
 result = false;
 }
}
 return result;
}

Find the Longest Word in a String:

function findLongestWord(str) {
 var arrStr = str.split(' ');
 var maxLength=0;
 
 for(var i=0;i<arrStr.length;i++){
 maxLength = Math.max(arrStr[i].length,maxLength);

}
 return maxLength;
}

Change the String to Title Case:

function titleCase(str) {
 var arrStr = str.split(' ');
 
 for(var i=0; i<arrStr.length; i++){
 arrStr[i] = arrStr[i].charAt(0).toUpperCase() + arrStr[i].substr(1).toLowerCase();
 }
 
 str = arrStr.join(' ');
 return str;
}

 Shift Cipher (Unshift by 13):

function rot13(str) { 
 var resultStr = '';
 
 for(var i=0; i<str.length; i++){
 if(str.charCodeAt(i)>=65 & str.charCodeAt(i)<=90){
 if(str.charCodeAt(i)<78){
 resultStr+= String.fromCharCode(str.charCodeAt(i)+13);
 }else{
 resultStr+= String.fromCharCode(str.charCodeAt(i)-13);
 }
 }else{
 resultStr+= str.charAt(i);
 }
 }
 return resultStr;
}

 



Leave a comment

About Me

Senior Software Engineer professional with over 16 years of success with multiple open source technologies and various Content Management platforms and solutions.

Proven technical abilities through numerous projects involving enterprise web application design and development, application installation, configuration and support, and workflow and collaboration system designs.

  • Ability to learn new technologies and platforms quickly and apply them to the task at hand.
  • Excellent analytical skills, and strong communication and collaboration abilities.
  • Technical emphasis in including but not limited to Java, Ruby on Rails, Documentum and Alfresco
    in both Linux and Windows based environments

Newsletter