-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_function.js
More file actions
67 lines (53 loc) · 1.43 KB
/
array_function.js
File metadata and controls
67 lines (53 loc) · 1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
// //1st
// function checkAddElements(arr,elem){
// if(arr.includes(elem)===false){
// arr.unshift(elem)
// return arr
// }
// else{
// return "element already exists"
// }
// }
// console.log(checkAddElements([1,2,3,4],6))
// //2nd
// function cancArr(arr1,arr2){
// return arr1.concat(arr2)
// }
// console.log(cancArr(["Hello","Ji","javascript"],["I","am","amazing"]))
//3rd
function sliceAndSplice(arr){
let x=(arr.slice(2,5));
console.log(x)
let y=x.toSpliced(1,0,'hello')
console.log(y)
}
sliceAndSplice([1,2,3,4,5,6,7])
//4th
// const originalNames=['Alice','Bob','Charlie']
// const newNames=['Arnab','Boro','Das']
// let Allnames=[...originalNames,...newNames]
// function printNamesWithGreeting(names){
// for(let i of names){
// console.log("Hello "+i+" !")
// }
// }
// printNamesWithGreeting(Allnames)
//5th
// const firstNames=['John','Alice']
// const lastNames=['Doe','Smith']
// function combineNames(firstNameArr,lastNameArr){
// let fullName=[]
// for(let i=0;i<firstNameArr.length;i++){
// fullName.push(firstNameArr[i]+" "+lastNameArr[i])
// }
// return fullName
// }
// const fullNames=combineNames(firstNames,lastNames)
// console.log(fullNames)
//6th
// const numbers=[7,2,9,1,4,6]
// function sortAscending(arr){
// return arr.sort()
// }
// const sortedNumbers=sortAscending(numbers)
// console.log(sortedNumbers)