Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 25f40d5

Browse files
1 file modified
1 parent 7bb3d06 commit 25f40d5

File tree

1 file changed

+32
-27
lines changed

1 file changed

+32
-27
lines changed

‎src/App.js

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import './style.css';
44
Differences between forEach() and map() methods:
55
The forEach() method does not returns a new array based on the given array. The map() method returns an entirely new array. The forEach() method returns "undefined". The map() method returns the newly created array according to the provided callback function.1
66
*/
7+
8+
// ======Map vs forEach===========
9+
710
const numArr = [1, 2, 3];
811
const res = numArr.map((el) => el * 2);
912
console.log(numArr, res);
@@ -12,13 +15,13 @@ const res2 = numArr.forEach((val, i, arr) => (arr[i] = val * 2));
1215
console.log(numArr, res2);
1316

1417
const person = {
15-
name: "Deepak",
18+
name: 'Deepak',
1619
age: 28,
17-
printInfo: function() {
20+
printInfo: function() {
1821
console.log(`My name is ${this.name} and my age is ${this.age}`);
19-
}
20-
}
21-
person.printInfo()
22+
},
23+
};
24+
person.printInfo();
2225

2326
export default function App() {
2427
const ERROR_MSG = 'Age is less than 18';
@@ -42,42 +45,44 @@ export default function App() {
4245
);
4346
}
4447

48+
// ============Merge 2 duplicate array and sort===========
49+
4550
const sortDup = (arr) => {
4651
const removeDup = (arr) => {
4752
let uniq_arr = [];
48-
for(let i=0;i<arr.length;i++){
49-
let isUniq = false;
50-
let element = arr[i];
51-
// debugger
52-
for(let j=0;j<uniq_arr.length;j++){
53-
if(element===uniq_arr[j]){
54-
isUniq = true;
55-
break;
56-
}
57-
}
58-
if(!isUniq){
59-
uniq_arr.push(element);
53+
for (let i = 0; i < arr.length; i++) {
54+
let isUniq = false;
55+
let element = arr[i];
56+
// debugger
57+
for (let j = 0; j < uniq_arr.length; j++) {
58+
if (element === uniq_arr[j]) {
59+
isUniq = true;
60+
break;
6061
}
62+
}
63+
if (!isUniq) {
64+
uniq_arr.push(element);
65+
}
6166
}
6267
return uniq_arr;
63-
}
68+
};
6469
var newArr = removeDup(arr);
6570
const sorting = (newArr) => {
66-
for(let i=0;i<newArr.length;i++){
67-
for(let j=0;newArr.length-i;j++){
68-
if(newArr[j]>newArr[j+1]){
71+
for(let i=0;i<newArr.length;i++){
72+
for(let j=0;newArr.length-i;j++){
73+
if(newArr[j]>newArr[j+1]){
6974
// [newArr[j], newArr[j+1]] = [newArr[j+1], newArr[j]];
7075
let temp = newArr[j];
71-
newArr[j] = newArr[j+1];
72-
newArr[j+1] = temp;
76+
newArr[j] = newArr[j+1];
77+
newArr[j+1] = temp;
7378
}
7479
}
7580
}
7681
return sorting(newArr);
77-
}
82+
};
7883
return newArr;
79-
}
80-
var Arr_A=["Ramesh","Suresh","Deepak","Suresh","Gopi"];
81-
var Arr_B=["Gopi","vendeesh","Deepak","Vedneesh"];
84+
};
85+
var Arr_A=['Ramesh','Suresh','Deepak','Suresh','Gopi'];
86+
var Arr_B=['Gopi','vendeesh','Deepak','Vedneesh'];
8287
var arr = [...Arr_A, ...Arr_B];
8388
console.log(sortDup(arr));

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /