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 ab65e09

Browse files
solved some tasks related to the Array and String methods
1 parent 8dc1375 commit ab65e09

File tree

6 files changed

+172
-14
lines changed

6 files changed

+172
-14
lines changed

‎Array methods/script.js

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,8 @@
9494
// } )
9595
// console.log(lettersLenght);
9696
// const numbers = [10,20,30,40,50];
97-
// const discountPrice = numbers.map(item=>{
98-
// return item - (item / 10)
99-
// })
97+
// const discountPrice = numbers.map(item=> item - (item / 10)
98+
// )
10099
// console.log(discountPrice)
101100

102101

@@ -195,10 +194,11 @@
195194
/// SLICE METHOD //
196195

197196
// const numbers =[1,2,3,4,5]
198-
// // const num2 = numbers.slice(1,4)
199-
// const num2 = numbers.slice(-5)
197+
// const num3 = numbers.slice(1,4)
198+
// const num2 = numbers.slice(-Infinity)
200199
// console.log(num2);
201-
// console.log(numbers);
200+
// console.log(num3);
201+
// console.clear()
202202

203203

204204
// const participants = ['Alice','Patrick','Malvina','Johanna'];
@@ -277,10 +277,11 @@
277277

278278
// REVERSE METHOD //
279279
// const numbers = [1,2,3,4,5];
280-
// // const newArr = numbers.concat().reverse();
280+
// const newArr1 = numbers.concat().reverse();
281281
// const newArr = [...numbers].reverse();
282282
// console.log(newArr);
283-
// console.log(numbers);
283+
// console.log(numbers);
284+
// console.log(newArr1);
284285

285286
// const str = ['Coding is fun! '];
286287
// const res = str
@@ -533,4 +534,21 @@
533534
// num++;
534535
// }
535536
// })
536-
// console.log(num);
537+
// console.log(num);
538+
539+
// const numbers = [];
540+
// for(let i = 0;i<=100;i++){
541+
// numbers.push(i)
542+
// }
543+
// console.log(numbers);
544+
545+
// numbers.sort((a,b) =>{
546+
// if( a % 2 == 0 && b % 2 !==0){
547+
// return -1
548+
// }else if( a % 2 !== 0 && b % 2 ==0){
549+
// return 1
550+
// }else {
551+
// return 0;
552+
// }
553+
// })
554+
// console.log(numbers);

‎Array methods/tempCodeRunnerFile.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
const numbers =[1,2,3,4,5,5,4,3,6,7,8];
2+
const res = Array.from(new Set(numbers));
3+
console.log(res)

‎CheatSheet for Array methods JS.txt

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
Array methods CheatSheet:
2+
3+
Method Name: forEach()
4+
Example Update each element in an array by multiplying it by 2.
5+
6+
const numbers = [1, 2, 3, 4, 5];
7+
8+
numbers.forEach(function(number, index, array) {
9+
array[index] = number * 2;
10+
});
11+
12+
console.log(numbers);
13+
14+
Does it mutate the source or not: The forEach() method does not mutate the source array. It only performs an operation on each element of the array without modifying it.
15+
16+
Argument List and Meaning:
17+
18+
callback (required): The function to execute on each element. It takes three arguments:
19+
currentValue: The current element being processed in the array.
20+
index (optional): The index of the current element being processed.
21+
array (optional): The array that forEach() is being applied to.
22+
What it returns: The forEach() method does not return anything. It performs an operation on each element of the array, but it does not produce a new array or a return value.
23+
24+
------------------------------------------------------------------------------------------------------------------------------------------
25+
26+
Method Name: map()
27+
28+
Example 1: Double each element in an array.
29+
30+
const numbers = [1, 2, 3, 4, 5];
31+
32+
const doubledNumbers = numbers.map(function(number) {
33+
return number * 2;
34+
});
35+
36+
console.log(doubledNumbers);
37+
38+
39+
Does it mutate the source or not: The map() method does not mutate the source array. It creates a new array with the results of calling a provided function on each element of the original array.
40+
41+
Argument List and Meaning:
42+
43+
callback (required): The function to execute on each element. It takes three arguments:
44+
45+
currentValue: The current element being processed in the array.
46+
index (optional): The index of the current element being processed.
47+
array (optional): The array that map() is being applied to.
48+
What it returns: The map() method returns a new array with the results of calling the provided function on each element of the original array.
49+
50+
Please note that the arrow function syntax can also be used instead of traditional function syntax in the examples.
51+
52+
------------------------------------------------------------------------------------------------------------------------------------------
53+
54+
Method Name: filter()
55+
56+
Example: Filter out even numbers from an array.
57+
58+
const numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
59+
60+
const evenNumbers = numbers.filter(function(number) {
61+
return number % 2 === 0;
62+
});
63+
64+
console.log(evenNumbers);
65+
66+
Does it mutate the source or not: The filter() method does not mutate the source array. It creates a new array containing elements that pass the specified filtering condition.
67+
68+
Argument List and Meaning:
69+
70+
callback (required): The function to test each element of the array. It takes three arguments:
71+
72+
currentValue: The current element being processed in the array.
73+
index (optional): The index of the current element being processed.
74+
array (optional): The array that filter() is being applied to.
75+
What it returns: The filter() method returns a new array with the elements that pass the filtering condition specified by the provided function.
76+
77+
Please note that the arrow function syntax can also be used instead of traditional function syntax in the example.
78+
79+

‎String methods/script.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,10 +193,10 @@
193193
// SYNTAXES //
194194
//string.matchAll()
195195
// let text = 'The rain in SPAIN stays mainly in the plain';
196-
// // let s = text.matchAll('ain')//it returns all matched strings inside referenceString and their position all stuff
197-
// // console.log(...s);
198-
// // let a = text.matchAll(/ain/g)////it returns all matched strings inside referenceString and their position all stuff
199-
// // console.log(...a);
196+
// let s = text.matchAll('ain')//it returns all matched strings inside referenceString and their position all stuff
197+
// console.log(...s);
198+
// let a = text.matchAll(/ain/g)////it returns all matched strings inside referenceString and their position all stuff
199+
// console.log(...a);
200200
// let b = text.matchAll(/ain/gi)////it returns all matched strings inside referenceString and their position all stuff but both cases lowercase and upperCase
201201
// console.log(...b);
202202
// let e = text.matchAll(/w/gi)//if method failed it returns empty array [];
@@ -302,4 +302,5 @@
302302

303303
// SYNTAXES //
304304
// String.raw(strings,...substitution)
305-
//String.raw'templateStrings'
305+
//String.raw'templateStrings'
306+

‎String methods/tempCodeRunnerFile.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log(numbers);

‎interview.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
// const num = [1,2,3,4,5,6,7,8,9,10];
2+
// num.forEach(item =>{
3+
// console.log(item);
4+
// })
5+
// function double(arr){
6+
// return arr.map(item => item * 2)
7+
// }
8+
// console.log(double(num))
9+
// const even = num.filter(value => value % 2 == 0)
10+
// const odd =num.filter(value => value % 2 !== 0)
11+
// console.log(even);
12+
// console.log(odd);
13+
// const sumEv = even.reduce((acc,num)=>{
14+
// return acc + num
15+
// });
16+
// console.log(sumEv);
17+
18+
19+
// const sumOdd = odd.reduce((acc,num)=>{
20+
// return acc + num
21+
// })
22+
// console.log(sumOdd);
23+
// console.log(num[num.length -1]);
24+
// const c = even.concat(odd)
25+
// console.log(c);
26+
// const isEven = even.every(value => value % 2 ==0)
27+
28+
// const arr = new Array(100).fill(1)
29+
// const arr1 =[2, 3, 4,[5, 6, 7, [5, 6, 7, 9]], [5, 6, 7]]
30+
// const arr2 = arr1.flat(Infinity)
31+
// const is = Array.isArray(arr1)
32+
// console.log(is);
33+
34+
// includes()
35+
// IndexOf()
36+
// find()
37+
38+
39+
// const names = ['Ali','tim','kim','tom']
40+
// console.log(names.join('-'));
41+
42+
// const arrStr = names.join('-')
43+
44+
// const names2 = names.slice(1,3)
45+
46+
// const str = ' Mohammed Moin khan '
47+
// console.log(str.trim());
48+
49+
// at
50+
// isArray()
51+
// splice()
52+
53+
const num = [1,2,3,4,5,6,7];
54+
const str = 'Rim skdfokfokefe'
55+
console.log(num.at(0));
56+
console.log(str.at(0));

0 commit comments

Comments
(0)

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