JavaScript coding Interview questions | reactjs interview questions | TCS | Capgemini | Must watch

JavaScript coding Interview questions | reactjs interview questions | TCS | Capgemini | Must watch

code with huma

1 год назад

8,210 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@hskhan824
@hskhan824 - 24.09.2023 14:48

Nice

Ответить
@shahbazshael8496
@shahbazshael8496 - 11.09.2023 18:44

Very helpful 👍

Ответить
@vamsim5911
@vamsim5911 - 01.09.2023 20:37

for the last question we can reduce the code like :
const obj = {}

array.forEach(item => {
obj[item] = obj[item]? obj[item] +1 : 1
})
console.log(obj)

Ответить
@nicholasleask1159
@nicholasleask1159 - 23.05.2023 23:53

I think there are better solutions for the first one, this was mine. It completes in constant time:

function rotate(arr, n){
return [...arr.slice(arr.length - (n % arr.length)), ...arr.slice(0, arr.length - (n % arr.length))];
}

Effectively it's grabbing the back and putting it on the front. It also account for values of n over arr.length using modular.

Ответить
@sourabhkulkarni1731
@sourabhkulkarni1731 - 23.01.2023 08:25

Super

Ответить
@deepanshugoyal1250
@deepanshugoyal1250 - 29.12.2022 13:49

for the last Question my code was
let arr = ["a", "b", "a", "c", "a", "b", "d"];
let obj= {};
for(let x of arr){
if( !obj[x]){
obj[x] =1;
}else{
obj[x]++;
}
}
console.log(obj);

Ответить
@deepanshugoyal1250
@deepanshugoyal1250 - 29.12.2022 13:32

for second question my approach was that..randomly
let str1 ="codehelpeee e";
let str2 = "decolhpee eee";
function compareStrCharacters(str1,str2){

for( let i=0; i<str1.length;i++){
char = str1[i];
index =str2.indexOf(char);
if(str2.includes(char)){
str2 = str2.slice(0,index)+str2.slice(index+1);

}else {
return false
}
}
return true;
}
console.log( compareStrCharacters(str1, str2));

I know but as you said I tried thank u.

Ответить
@deepanshugoyal1250
@deepanshugoyal1250 - 29.12.2022 13:05

To be very Genuine I followed the same approach for the first questions Mam.

Ответить
@tusharchemate1068
@tusharchemate1068 - 23.11.2022 16:28

Q3 !! optimised this way also.

const arr =['aaa','bbb','ccc','aaa','bbb'];
let obj = {};
arr.map((item) => {
obj[item] ? obj[item] +=1 : obj[item] = 1;
});
console.log(obj);

Ответить
@kmrsandeepkmr
@kmrsandeepkmr - 21.11.2022 23:26

Very helpful. Thanks Huma.😍

Ответить
@ariba7770
@ariba7770 - 10.10.2022 17:17

👍

Ответить