Skip to content

Commit 4c53dcc

Browse files
authored
Update js codes.docx
1 parent 3527755 commit 4c53dcc

1 file changed

Lines changed: 30 additions & 0 deletions

File tree

‎js codes.docx‎

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2709,3 +2709,33 @@ console.log(UpdatedAge)
27092709
const UpdatedAge= Age.filter((item)=>(item>5))
27102710
console.log(UpdatedAge)
27112711
=====================================================================================================================================================================
2712+
sort:-
2713+
const Data =[11,44,2,66,3,7,22,3]
2714+
const sorted= Data.sort((a,b)=>{
2715+
if(a>b) return 1;
2716+
else return -1;
2717+
})
2718+
console.log(sorted) //prefer for object
2719+
//a<b //[66,44,22,11,7,3,3,2]
2720+
//a>b //[2,3,3,7,11,22,44,66]
2721+
2722+
2723+
const sorted1= Data.sort((a,b)=>b-a)
2724+
console.log(sorted1) //prefer for arrays
2725+
//b-a //[66,44,22,11,7,3,3,2]
2726+
//a-b //[2,3,3,7,11,22,44,66]
2727+
======================================================================================================================================================================
2728+
Reduce:
2729+
const Data =[11,44,2,66,3,7,22,3]
2730+
var updatedData=0;
2731+
for(var i=0; i<Data.length; i++){
2732+
updatedData=updatedData+Data[i]
2733+
}
2734+
console.log(updatedData)
2735+
----------------
2736+
const updated= Data.reduce((acc, item)=>{
2737+
return acc+item
2738+
},0)
2739+
2740+
console.log(updated)
2741+
======================================================================================================================================================================

0 commit comments

Comments
 (0)