diff --git a/Task1.js b/Task1.js new file mode 100644 index 0000000..13014e6 --- /dev/null +++ b/Task1.js @@ -0,0 +1,30 @@ +function GroupByKey(array,key) +{ + const tempData = {}; + + for ( var index=0; index{ + if(!accumulator[currentvalue[key]]){ + accumulator[currentvalue[key]]=[] + } + accumulator[currentvalue[key]].push(currentvalue) + tempobj=accumulator + return accumulator + },{}); + return tempobj + +} + +console.log(GroupByKey(array,key)) diff --git a/Task3.js b/Task3.js new file mode 100644 index 0000000..968d5e8 --- /dev/null +++ b/Task3.js @@ -0,0 +1,31 @@ +const array=[ + {id:'one',next:"two", value:null}, + {id:'two',next:"three", value:null}, + {id:'three',next: null, value:null} +]; +var result=[] + +function updatearray(arr){ + for(var i=arr.length-1; i>-1;i--){ + updatevalue(arr[i]) + } +} + +function updatevalue(ele){ + if(ele.next==null){ + return (result.unshift(ele)) + } + else{ + for(var j in array){ + if(result[0].id==array[j].next){ + array[j].value=result[0] + result.unshift(array[j]) + break + } + } + } +} +updatearray(array) +result=JSON.stringify(result); +console.log(result) +// console.log(result[0].value) \ No newline at end of file diff --git a/Task4.js b/Task4.js new file mode 100644 index 0000000..109f3f2 --- /dev/null +++ b/Task4.js @@ -0,0 +1,29 @@ +const array=[ + {id:'one',next:"two", value:null}, + {id:'two',next:"three", value:null}, + {id:'three',next: null, value:null} +]; +var result=[] +function updatevalue(array){ + if(result.length==0){ + for(var i in array){ + if(array[i].next==null){ + result.unshift(array[i]) + array.splice(array[i],1) + } + } + } + for(var j in array){ + if(result[0].id==array[j].next){ + array[j].value=result[0] + result.unshift(array[j]) + array.splice(array[j],1) + updatevalue(array) + break + } + } + +} +updatevalue(array.reverse()) + +console.log(result) \ No newline at end of file diff --git a/Task5.js b/Task5.js new file mode 100644 index 0000000..44a95ce --- /dev/null +++ b/Task5.js @@ -0,0 +1,23 @@ +const array=[ + {id:'one',next:"two", value:null}, + {id:'two',next:"three", value:null}, + {id:'three',next: null, value:null} +]; +var nextindex=0 +function updatearray(array){ + updatevalue(array,0) + function updatevalue(array,index){ + if(array[index].next==null){ + return array[index] + } + else{ + array[index].value=updatevalue(array,index+1) + return array[index] + } + } +} + +updatearray(array) +var arr=array +arr=JSON.stringify(array) +console.log(arr) \ No newline at end of file diff --git a/Task6.js b/Task6.js new file mode 100644 index 0000000..9878aa2 --- /dev/null +++ b/Task6.js @@ -0,0 +1,22 @@ +function delay(time) { + return new Promise((resolve, reject) => { + if (typeof(time) === 'string') { + console.log() + reject(new Error("Delay required a valid number")); + } + else{ + time *= 1000; + setTimeout(resolve, time); + } + }); +} + +async function main() { + await delay(2); + console.log("saad"); + await delay(2); + console.log("fareed"); + await delay(2); + console.log("happy Birthday"); +} +main();