Magic edtech
https://codepen.io/ankittyagi206/pen/GRLbRNy
// function outer(x){
// return function(y){
// return x*y;
// }
// }
// console.log(outer(3)(4))
//map --> [] --> []
const obj={
name:'ankit'
}
const obj2= {...obj,...{
age:26
}}
delete obj2.name
console.log(obj2,obj)
deep copy shallow copy
promises async await
// Given a string S containing alphanumeric characters,
// The task is to calculate the sum of all numbers present in the string.
// Output: 24
// Explanation: 1 + 23 = 24
// const input= '1abc22'
// function calculateSum(input){
// let numArr =[];
// for(let i=0; i<input.length;i++){
// if(+input[i] && +input[i+1]){
// let newNum=Number([input[i],input[i+1]].join(''));
// numArr.push(newNum)
// }
// else if(+input[i] && input[i+1] !=undefined && !(+input[i+1])){
// numArr.push(Number(input[i]))
// }
// else{
// //do nothing
// }
// }
// let sum=0;
// for(let el of numArr){
// if(+el){
// sum+=Number(el)
// }
// }
// return sum
// }
// console.log(calculateSum(input))
// // How to flat this array:
// const a1 = [1, [2,[3,4,5], 6], 7, 8, 9, [10], 11] ;
// // Output: const a1 = [1, 2,3,4,5, 6, 7, 8, 9, 10, 11] ;
// const flattenArray =(arr,newArr=[])=>{
// for(let el of arr){
// if(Array.isArray(el)){
// //if it is an array
// flattenArray(el,newArr)
// }
// else{
// newArr.push(el)
// }
// }
// return newArr
// }
// console.log(flattenArray(a1))
//1,2,3,7,6,12,4,'foo'
console.log(1) //1
let promise= new Promise((resolve,reject)=>{
console.log(2)//2
setTimeout(() => {
console.log(12)
resolve('foo');
}, 10);
})
console.log(3)//3
promise
.then(data=>{
console.log(4,data)
})
.catch(data=>{
console.log(5,data)
})
console.log(7)//4
setTimeout(()=>{
console.log(6)
},0)
Comments
Post a Comment