Untitled

 avatar
user_7147158
plain_text
5 months ago
2.0 kB
10
Indexable
// question - 1
// i/p-> aabcccadbb
const str = "aabcccadbb"
function getCount(){
    let obj = {};
    for(let i=0;i<str.length;i++){
        if(obj[str[i]]){
            obj[str[i]] = obj[str[i]]+1
        }
        else{
            obj[str[i]] = 1;
        }
    }
    console.log(obj)
}
const count = getCount();
// console.log(count)




// question - 2
// Find the largest third element in the array .
const arr = [11,5,7,22,9,25];

for(let i=0;i<arr.length;i++){
    for(let j=0;j<arr.length;j++){
        if(arr[j] < arr[j+1]){
            let temp = arr[j];
            arr[j] = arr[j+1];
            arr[j+1] = temp;
        }
    }
}
console.log(arr[2])
// do it in O(n)





// question - 3
// i/p-> aabcccadbb
// o/p-> aa2b1ccc3a1d1bb2 
const str = 'aabcccadbb';
let temp = [];
let count =0;
for(let i=0;i<str.length;i++){
    if(str[i] === str[i+1]){
        count++;
        temp.push(str[i])
    }
    else{
        count = count + 2;
        temp.push(str[i],--count);
        count = 0;
    }
}
// console.log(temp.join(''))
let newStr = '';
for (let i=0;i<temp.length;i++){
    newStr = newStr + temp[i];
}
console.log(newStr)




// var test = 1;
// function functionHoisting() {
//   test = 10;
//   return;
// function test() {}
// }
// functionHoisting();
// console.log(test);
a:
function a(){
  console.log("hello")
  console.log("1")
}
a();
function a(){
  console.log("2")
}
a();

// function hoistingExample() {
//   console.log("local scope: ", a);
// }
// console.log("global scope: ", a);
// var a = 1;
// hoistingExample();


// console.log('start');
// const promise1 = new Promise((resolve, reject) => {
// 	console.log(1)
// })
// promise1.then(res => {
// 	console.log(2)
// })
// console.log('end');



// theory js question - 
1 - hoisting question
2 - simple function and arrow function 
3 - Promise method 
4 - Promise api
5 - Promise.any and Promise.race difference

// react 
types of hooks
use reducer hook
redux
redux thunk
Editor is loading...
Leave a Comment