OneCompiler

output based 2

217

Example heading with h2 size

Example heading with h3 size

Following is sample java code.


// 1.What will be the output of the following code:
 
// for (var i = 0; i < 5; i++) { 
//   setTimeout(function() { 
//     console.log(i);
//     }, i * 1000 );
//   }

 
// // 5
 
// 2. In what order will the numbers 1-5 be logged to the console when the code below is executed? Why?
 
// (function() { 
//   console.log(1);
//   setTimeout(function(){
//     console.log(3)
    
//   }, 1000); 
  
//   setTimeout(function(){
//       console.log(2)
  
//   }, 0); 

//   console.log(5); 
  
// }
// )();

// // 1,5, 2,3
 
 
// 3.What is the output of the following code?
 
// var length = 10; 
 function fun() { 
  this.a=10
  console.log(this.name); 
  
}
//fn()
var obj = { 
  length: 5,
  method: function(fn) { 
    fn(); 
    console.log(arguments)
    //[0]();
  }
  
};
var obj2 = { 
  length: 5,
  method: function(fn) { 
    fn(); 
    console.log(arguments)
    //[0]();
  }
  
};
console.log(obj === obj2)
var str=`adf fsds fds ggg

	sfs abc fsd

	re fd fkd`
	
	console.log([...str])
 
// str = [

// 	['adf', 'fsfds', 'fds', 'ggg'],

// 	['sfs', 'abc', 'fsd'],

// 	['re', 'fd', 'fkd']

// ]
 
//obj.method(fn, 1);
//5, 5



// Flatten following array without using array.flat
// [1,2,[3,4], [5, [6, 7,[8,[9]]]]] into -> [1,2,3,4,5,6,7,8,9]

// const arr = [1,2,[3,4], [5, [6, 7,[8,[9]]]]];
// let flatten = []
// function flat(array){
  
//   for(let i=0; i<array.length; i++){
//     if(Array.isArray(array[i])){
//       flat(array[i])
//     } else {
//       flatten.push(array[i])
//     }
//   }
  
//   return flatten;
  
// }

// console.log(flat(arr))

//Given the following array: 
// const users = [
// { id: 1, name: 'John Doe', age: 25 }, 
// { id: 2, name: 'Jane Smith', age: 30 },
// { id: 3, name: 'Sam Johnson', age: 20 },
// ];
//Write a function that returns an array of user names sorted by age in descending order.



// const sorted = () =>{
// let temp=[]
// const sorted = []

// users.forEach((user)=>{
// temp.push(user.age)
// })

// temp.sort((a,b)=>a>b).forEach((userAge)=>{
//   users.forEach((item)=>{
//     if(userAge ===item.age) {
//       sorted.push(item.name)
//     }
//   })
// })
// return sorted;

// }
// console.log(sorted())
// let obj = {'a': 5};
// let f = (o) => o = {'a': 3};

// console.log(f(obj)); 


 



const arr = [1,2,2,3,3,3,4]
//output {'1': 1, '2': 2,'3':3,'4':1}

const output = arr.reduce((acc, item)=>{
 
  if(acc[item]){
    acc[item]+=1
  } else {
     acc[item] =1
  }
  return acc;
},{})

console.log(output)

const user = {
  id: 111,
  name: 'X',
  age: 20,
  education: {
    degree: 'Masters'
  }
};

const {education:{degree}} = user


const closerz = () =>{
  let a=10
  return ()=>{
    console.log(a)
  }
}

closerz()()










a()
function a(){
  const num = 10;
 return function b(){
   console.log(num)
   
 }
}

a()

// const a = ()=>{
  
// }

let actors = [
    {
      id: '1',
      name: 'Aamir Khan',
      age: 57,
    },
    {
      id: '2',
      name: 'Salman Khan',
      age: 56,
    },
    {
      id: '3',
      name: 'Tiger Shroff',
      age: 32,
    },
];
  
let Movies = [
  {
    id: '1',
    actorId: '1',
    name: '3 Idiots',
    rating: 8.4,
  },
  {
    id: '1',
    actorId: '1',
    name: 'Talaash',
    rating: 2,
  },
  {
    id: '2',
    actorId: '2',
    name: 'Bajranji Bhaijan',
    rating: 3.1,
  },
  {
    id: '2',
    actorId: '2',
    name: 'Tere Naam',
    rating: 4.5,
  },
  {
    id: '2',
    actorId: '2',
    name: 'Andaz Apna Apna',
    rating: 8.1,
  },
  {
    id: '3',
    actorId: '3',
    name: 'Heropanti',
    rating: 3.5,
  },
];


const actorAge = (limit=50) =>{
  const output = []

   Movies.forEach((movie, index)=>{
    actors.forEach((actor)=>{
      
      if(actor.age > limit && movie.actorId === actor.id) {
        
        output.push(movie.name)
      }
    
    })
  })

return output;
}

console.log(actorAge())




// p - Movies List for Actors whose age is >50


// has context menu




// based on spaces we need to revers
// split with spaces
//loop indusuals
Arr = i

let currentString = ‘’
for(let i=0; i<arr.length;i++) {
	
  Const newVal = arr[i].split(‘’)
for(let j=newVal.length-1; j>=0;  j - - ){
	currentString += j ===0 ? “ ” : newVal[j]

}
	
}

//# 1
// Task: calculate the number of identical elements
// You need to output the number of repetitions of elements for each element to the console.
// Example: "value - quantity in the object"
// for this object - { a: 3, b:  1, c: 2, d: 1 }
const obj1 = {
  1: 'a',
  2: 'b',
  3: 'a',
  4: 'c',
  5: 'a',
  6: 'd',
  7: 'c',
};

//# 2
// Increment elements that are larger than the previous one in the original array
const ar = [4, 5, 6, 7, 8, 9, 2, 0, 3, 0];

//# 3
// What will be output to the console?
// let obj = {'a': 5};

// let f = (o) => o = {'a': 3};

// f(obj);
// console.log(obj.a);

//# 4
// const object = {
//   name: "John",
//   hi() {
//     console.log(`Hello, ${this.name}!`);
//   }
// };

// setTimeout(object.hi, 1000);



//  sort
// find repeated
// find missed


2.

// sort
// i can find max val
// restore all from min to max



const arr = [1,2,3,4,5,5,6,6,7,8];

const sorted  = arr.sort((a,b)=>())



const some = (input) => {
	var some = 0;
  let some;
 
	for(let i = 1; i  <= input; i++) {
		some= some + i 
	
	}
        return some

}


console.log(0.1 + 0.2 === 0.3)
let lang = 'javascript'; (function(){  ... by Shoaib Mansoor (Unverified)Shoaib Mansoor (Unverified)4:04 pm
let lang = 'javascript';
(function(){
   let lang = 'java';
})();
 
console.log(lang);
(function(){
   var lang2 = 'java';
})();
console.log(lang2);
for (var i = 0; i < 3; i++) {   setTimeou... by Shoaib Mansoor (Unverified)Shoaib Mansoor (Unverified)4:05 pm
for (var i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}
 
for (let i = 0; i < 3; i++) {
  setTimeout(() => console.log(i), 1);
}
console.log(1);   setTimeout(function () { ... by Shoaib Mansoor (Unverified)Shoaib Mansoor (Unverified)4:08 pm
console.log(1);
 
setTimeout(function () {
  console.log(2);
}, 0);
 
Promise.resolve()
  .then(function () {
    console.log(3);
  })
  .catch(function () {
    console.log(3.1);
  })
  .then(function () {
    console.log(4);
  });
console.log("begins");   setTimeout(() => {... by Shoaib Mansoor (Unverified)Shoaib Mansoor (Unverified)4:09 pm
console.log("begins");
 
setTimeout(() => {
  console.log("setTimeout 1");
  Promise.resolve().then(() => {
    console.log("promise 1");
  });
}, 0);
 
 
new Promise(function (resolve, reject) {
  console.log("promise 2");
  setTimeout(function () {
    console.log("setTimeout 2");
    resolve("resolve 1");
  }, 0);
}).then((res) => {
  console.log("dot then 1");
  setTimeout(() => {
    console.log(res);
  }, 0);
});
Pair with largest sum which is less than K ... by Shoaib Mansoor (Unverified)Shoaib Mansoor (Unverified)4:15 pm
Pair with largest sum which is less than K in the array
Input : arr = [5, 20, 110, 100, 10], K = 85 
Output : 20, 10
Meeting ended: at 4:30 pm after 35 minutes 11 seconds 4:30 pm Meeting ended: 35m 11s DV, Yogesh (Cognizant) left the chat.DV, Yogesh (Cognizant) left the chat.has context menuYou can't send messages because you are not a member of the chat.has context menu