Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

reverseString / Palindrome / Split string / Reverse Array

//reverseString
function reverseString(str){
    return str.split("").reverse().join("");
}
console.log(reverseString("Raymund"));

//FisrtName LastName reverse Display
function nameDisplay(fn,ln) {
    const fname = fn.split("").join("");
    const lname = ln.split("").join("");
const reverse = lname +" " + fname ; 
return reverse;

}
console.log(nameDisplay("Raymund", "Alum"));

//Palindrome
function palindrome(str) {

    var len = str.length;
    var mid = Math.floor(len/2);

    for ( var i = 0; i < mid; i++ ) {
        if (str[i] !== str[len - 1 - i]) {
            return str +" is Not Palindrome";
        }
    }

    return str + " is a Palindrome";
}
console.log(palindrome("Raymund"));

//Split string-->
function splitPhoneNum(num) {
var string = num
var phone = [string.slice(0, 3), " ", string.slice(3)].join('');
return phone;
}
console.log(splitPhoneNum("+919911568974"));



 //<--Reverse Array-->
var arr=[1,2,5,6,2];

res = arr.reverse();

console.log(res);

 
PREVIOUS NEXT
Tagged: #reverseString #Palindrome #Split #string #Reverse #Array
ADD COMMENT
Topic
Name
6+4 =