![]() | |
|
Introduction:
Every javascript function has some logic for modification like toLowerCase(), toUpperCase(), join() and etc.. Today we are going to perform one program is revere string without any built-in function. Many developers doing this.
Challenge:
Write a logic for below input:
Input | Output |
---|---|
Javascript Everywhere | erehwyrevE tpirsavaJ |
Hello Developer | repoleveD olleH |
Was it a car or a cat I saw? | ?was i tac ro rac a ti saW |
Program Description: Write an algorithm to reverse a string without using any function provided by javascript. like reverse(), join(). Only allow length() is you really need.
1)
function reverseString(str) {
var reversedString = '';
for(let i= str.length - 1; i >= 0; i--)
{
reversedString += str[i];
}
return reversedString;
}
Another program with reverse and other function:
2)
"Javascript Developer improve skill here".split('').reverse().join('');
3)
"Jsgrip is website for developer".split('').reduce((temp1, temp2) => temp2 + temp1);
Explanation: Using array creates one variable blank and then inside for loop starting from the length of string and end to 0. From the last index assign value to the variable and after a loop just return that variable.
There are another way as well you can do achieve this output.
Other: Challenges here is Count lowercase, uppercase and number from string
https://jsgrip.blogspot.com/2020/04/javascript-challenges-count-lowercase.html