Тэги:
#coderdost #javascript_interview_question #javascript_interview #javascript_live_interview #javascript_coding_interview_questions #coding_round_in_placements #coding_round_questions_for_freshers #react_interview_questions #frontend_interview_questions #backend_interview_questions #javascript_in_urdu #javascript_in_hindi #react_js_in_urdu #react_js_in_hindiКомментарии:
Simple solution is
const a = "This is Javascript Code";
const reversedWords = a.split(' ').map(word => word.split('').reverse().join('')).join(' ');
console.log(reversedWords);
//output - "sihT si tpircsavaJ edoC"
const str = "This is JavaScript Code"
const splitString = str.split(" ");
let holdReversStr = "";
splitString.forEach((splitString) => { for(let i=splitString.length-1;i>=0;i--){ holdReversStr += splitString[i]} holdReversStr += " "} );
console.log(holdReversStr)
let wordArray=word.split(" ")
const reverseWord=wordArray.map(item=>item.split("").reverse().join(""))
console.log(reverseWord.join(" "))
const str = "this is javascript code";
let ans = str.split(" ").map((elm)=>elm.split('').reverse().join('')).join(" ");
console.log(ans);
const str = "harshit rajput"
const arr = str.split('')
// console.log(arr)
function h(arr){
let l =0;
let r=0;
let n = 0;
for(;r<arr.length;r++){
if(arr[r+1]===' ' || r===arr.length-1){
n = r+1
while(l<r){
let temp = arr[l]
arr[l] = arr[r]
arr[r] = temp
r--
l++
}
if(r===arr.length-1){
break;
}
l = n+1;
r = n;
}
}
return arr.join('')
}
console.log(h(arr))
ques1:
const str="This is JavaScript"
String.prototype.reverse=function(){
const newStr=str.split('').reverse().join('').split(' ').reverse().join(' ');
console.log(newStr)
}
str.reverse()
Sir i have a question are these mock interviews for the companies which prefer dsa students or the development companies
Ответитьlet text = "Hello everyone";
let arr2 = text.split(' ')
console.log(arr2)
let arr3 = arr2[0].toString().split('').reverse().join("")
let arr4 = arr2[1].toString().split('').reverse().join("")
console.log(arr3)
console.log(arr4)
const finalaray = arr3.concat(" "+arr4)
console.log(finalaray)
break everything into pieces first, then reverse it and join... easy to think easy to approach.
Great Content. Love from Pakistan
ОтветитьI have create word by word Reverse function without loop ;
var a = 'this is javascript code';
function reverseWord(a){
var b = a.split('');
b.reverse();
b = b.join('');
b = b.split(' ').reverse().join(' ');
console.log(b);
return b
}
reverseWord(a);
it will work !
console.log(str.split("").reverse().join("").split(" ").reverse().join(" "))
const maxWordCount=(str)=>{
const word = str.split(' ')
const maxArr = word.map((e)=>e.split('').length)
const output = Math.max(...maxArr)
return output
}
console.log(maxWordCount("this is javascript code"))
const message = "The rain in SPAIN stays mainly in the plain"
const result=message.toLocaleLowerCase().split(" ").join("")
console.log(result)
const maxcount=(result)=>{
const maxchar=[];
for(let i=0;i<result.length;i++)
{
const char=result.filter((val,ind)=> val === result[i]).length
maxchar.push(char)
}
return Math.max.apply(null, maxchar);
}
console.log(maxcount(result.split("")))
const str='This is a javascript code and you have to find mac char';
const strArr=str.split(' ');
let arr=[]
for (let i in strArr){
arr.push(strArr[i].split(''));
}
let counter={};
charArr=arr.flat();
charArr.forEach(item=>{
if(counter[item]){
counter[item]+=1;
}
else{
counter[item]=1;
}
})
console.log(counter)
const str="This is a Javascript code";
const strArr=str.split(' ');
let newStr="";
for(let i in strArr){
newStr+=strArr[i].split('').reverse().join('') + " "
}
console.log(newStr)
const ReverseString = (str) => {
const s = str.split(" ");
let dats = [];
for (let i = 0; i < s.length; i++) {
let dat = s[i].split("");
dats.push(dat.reverse().join(""));
}
const rev = dats.join(" ");
return rev;
};
This is more simple😅
let num = "this is a string"
a = num.split("")
let b = a.reverse()
let c = b.toString();
console.log(c)
I will solve question first with my method and approach then will be come to see how interviewer solve the question
ОтветитьAfter solving the many dsa question this question look likes the 1+1
ОтветитьHello sir.... Kya interview me jinki langwadge english hogi vhi interview de skta hai..?
Ответитьconst str = "This is Javascript Code!";
function reverseString(str) {
const splittedStr = str.split(' ');
let reversedStr = "";
for(let elem of splittedStr) {
reversedStr += elem.split('').reverse().join('') + ' ';
}
return reversedStr;
}
console.log(reverseString(str));
My answer to the Sum 1:
let string = "This is JavaScript Mock Interview";
let newS = "";
let stringBreak = string.split(" ");
for(let i of stringBreak){
var chars = i.split('');
var reversedChars = chars.reverse();
var reversedString = reversedChars.join('');
newS += " " + reversedString;
}
console.log(newS)
the code for this could as simple as this
output = []
input_arr.map((item, index) =>{
output.push(item.split('').reverse().join(''));
});
console.log(output.join(" "));
in the last problem you should have removed the empty string from the array. Otherwise, it would always give empty string has the largest count
Ответитьyes, we can using prototype
Ответитьreverse function is apply on the array only, not string or number
Ответитьconst str = "this is javascript code"
function isReverse(str){
let newStr = str.split(" ");
let result = []
for(let i =0;i<newStr.length; i++){
let innerStr = newStr[i].split('')
let tempResult = []
for(let j = innerStr.length-1; j >=0;j--){
tempResult.push(innerStr[j])
}
result.push(tempResult.join(''))
}
return result.join(' ')
}
const res = isReverse(str)
console.log(res)
Please add some difficult questions for person having more than 4+ years of experience.
ОтветитьSir, great content, inspirational
Ответитьstr.split(" ").map((i) => i.split("").reverse().join("")).join(" "); For the First Question : Reversing String Word wise not whole at once
Ответитьgreat content sir thank u for making this type of videos
Ответитьlet str="mabujani"
let res=[]
for(let i=0; i<str.length; i++)
{
if(res[str[i]])
{
res[str[i]]++
}
else
{
res[str[i]]=1
}
}
let max=""
let times=0
for(let char in res)
{
if(res[char]>times)
{
times=res[char]
max=char
}
}
console.log(times,max)
2nd:
const maxChar = (str) => {
let arr = str.split("");
let count = 0;
let res = "";
arr.forEach((ch) => {
let innercount = 0;
arr.forEach((el) => {
if (el == ch) {
innercount += 1;
}
});
if (innercount > count) {
count = innercount;
res = ch;
}
});
return res;
};
1st :
const rev = (str)=> {
let lineRev = inp.split(" ").reverse()
return lineRev.map(word=> word.split('').reverse().join("")).toString()
}
//reverse the string
function reverseString(str){
let tempAr=str.split(" ");
let finalAr=[];
tempAr.forEach(val=>{
let stringAr=val.split("");
let string='';
stringAr.forEach(val=>{
string=val+string;
})
finalAr.push(string);
})
return finalAr.join(" ");
}
reverseString("This is JavaScript Code")
// find max occuring char
function findMaxOccuringChar(str){
let tempStrAr=str.split("");
let object={};
tempStrAr.forEach(val=>{
if(object.hasOwnProperty(val))
object[val]++;
else
object[val]=1;
})
let maxChar=tempStrAr[0];
for(let i in object){
if(i!==" "&& object[i]>object[maxChar]){
maxChar=i;
}
}
return maxChar;
}
findMaxOccuringChar("This is JavaScript Code and you to find max char");
Easiest way 😉
let str = "Chutteee";
let strArr = str.split('');
let charCount = {}
strArr.forEach(char =>{
if(char !== ""){
if(Object.keys(charCount).includes(char)){
charCount[char]+=1
}
else{
charCount[char] = 1
}
}
});
let maxChar = {key:null,value:0};
Object.keys(charCount).forEach(k => {
if(charCount[k] > maxChar.value){
maxChar.value = charCount[k]
maxChar.key = k
}
});
console.log(maxChar);
Output : {key: 'e', value: 3}
come-up with single line approach
let result = str.split('').reverse().join('').split(' ').reverse().join(" ")
console.log(result)
Great
Ответитьlet str = "NodeJS is a javascript runtime";
const reverseWord = (str) => {
let arrStr = str.split(" ");
console.log(arrStr);
let newArrStr = arrStr.map((item) => {
return item.split("").reverse().join("");
});
return newArrStr.join(" ");
}
let res = reverseWord(str);
console.log(res);
let myStr = "This is javascript code and you to find max char";
let calculate = {};
function maxOccurring(str) {
for (let item of str) {
calculate[item] = (calculate[item] || 0) + 1;
}
let max = 0;
let finalResults;
for (let data in calculate) {
if (calculate[data] > max) {
max = calculate[data];
finalResults = {
[data]: max,
};
}
}
return finalResults;
}
console.log(maxOccurring(myStr.replaceAll(" ", "")));
var reverseWords = function (s) {
let res = "";
let word = "";
for (let c of s) {
if (c === " ") {
res += word + c;
word = "";
} else {
word = c + word;
}
}
return res + word;
};
Aapne jo code likha hai Ryan Dahl bhi dar jaye yaar mere se bada coder kon hai ye...Why you are making simple things complicated .. Here is the short,readable,understandable code const str = "I am the father of Javascript programming"
const splitText = str.split(' ')
const reversedSplit = splitText.map((word) => {
return word.split('').reverse().join('')
})
const finalreverse =reversedSplit.join(" ")
console.log(finalreverse)
js coding round ka playlist ka link dedo !!
ОтветитьCan't we apply the split method first and then print the array in reverse order
Ответитьlet arr= str.split(' ')
let out= new Array();
for(let i=0;i<arr.length;i++){
out[i]=arr[i].split('').reverse().join('');
}
console.log(out.join(' '));
function reverseString(str) {
let revArray = [];
let strlength = str.split(' ');
for (let i = 0; i < strlength.length; i++) {
let a = strlength[i].split("").reverse().join("");
revArray.push(a)
}
return revArray.join(" ")
}
console.log(reverseString("This is javascript code"))
yes, we can do that, first we have to make our function to reverse the string, the add the function to String.prototype, after this we can get that function in any where in the code.
Ответить