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 36144b5

Browse files
first commit
0 parents commit 36144b5

File tree

4 files changed

+193
-0
lines changed

4 files changed

+193
-0
lines changed

‎Loops2.js‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
var arr = [23, 45, 67, 56, 78, 21, 12]
2+
var arr1 = []
3+
var arr2 = []
4+
var arr3 = []
5+
let str = ''
6+
for(let i of arr)
7+
{
8+
arr1.push(i)
9+
}
10+
11+
arr.forEach(i=>{
12+
str = str + i +','
13+
})
14+
15+
for(let i=arr.length-1;i>=0;i--)
16+
{
17+
arr3.push(arr[i])
18+
}
19+
20+
console.log(arr1)
21+
console.log(arr2)
22+
console.log(arr3)
23+
console.log(str)

‎basics1_Variables.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
console.log("Hello World");
2+
3+
let a = 4
4+
const b = 5.67
5+
var c = "Ambuja"
6+
let d = true;
7+
const e = null;
8+
let f;
9+
console.log(typeof(a));
10+
console.log(typeof(b));
11+
console.log(typeof(c));
12+
console.log(typeof(d));
13+
console.log(typeof(e));
14+
console.log(typeof(f));
15+
16+
console.log(!d);
17+
18+
const t1 = Symbol(7878)
19+
console.log(t1)
20+
console.log(t1.description)
21+
console.log(t1.toString)
22+
23+
const student = {
24+
fname: 'Chitta',
25+
lname: 'Swain',
26+
age: 34,
27+
weight: '78'
28+
}
29+
student.fname = 'Ranjan'
30+
31+
console.log(student.fname)
32+
console.log(student)
33+
console.log(typeof(student.age))
34+
console.log(typeof(student.fname))
35+
console.log(++student.age)
36+
37+
38+
console.log(2=='2')
39+
40+
console.log(2==='2')
41+
42+
console.log(student.fname=='Ranjan')
43+
44+
delete student.fname
45+
console.log(student.fname)
46+
console.log(student)
47+
console.log(Number(student.weight))
48+
49+
console.log(student.weight===78)
50+
console.log(student.weight===String(78))
51+
52+
console.log(student.age.toString())
53+
54+
console.log(parseInt('20.66'))
55+
var aa = parseFloat('20.66')
56+
console.log(typeof(aa))
57+
58+

‎basics2_Loops.js‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const flag = true;
2+
if(!flag)
3+
{
4+
console.log("Condition met !");
5+
}
6+
else{
7+
console.log("Condition not met !");
8+
}
9+
let i=0;
10+
while(i<100)
11+
{
12+
console.log(i);
13+
i++;
14+
}
15+
let a=0;
16+
do{
17+
console.log("inside do while loop");
18+
a++;
19+
}while(a<10)
20+
21+
for(let k=1;k<=100;k++)
22+
{
23+
if(k%2==0 && k%5==0)
24+
{
25+
console.log(k)
26+
}
27+
}
28+
29+
30+
31+

‎basics3_Arrays.js‎

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
var marks = Array(6);
2+
var marks = new Array(20,34,45,56,67,78);
3+
4+
var list = [20,34,45,56,67,78];
5+
var list1 = [];
6+
7+
console.log(list[2]);
8+
list1[0]=10;
9+
console.log(list.length);
10+
list1.push(20); // Add an element at the end
11+
console.log(list1[1]);
12+
list.pop(); //delete last added element
13+
console.log(list);
14+
list1.unshift(5); //Add an element as the start
15+
console.log(list1);
16+
console.log(marks.indexOf(45)); //in which index the value is
17+
console.log(marks.includes(123)); //check whether the element is part of that array or not
18+
submarks = marks.slice(2,5); //Will print from 2 to 4 in marks array
19+
console.log(submarks);
20+
//Add all the elements present in the array
21+
var sum=0;
22+
for(let i=0;i<marks.length;i++)
23+
{
24+
//console.log(marks[i]);
25+
sum=sum+marks[i]
26+
}
27+
console.log(sum);
28+
29+
//reduce filter map
30+
let TotalMark = marks.reduce((sum,TotalMarks)=>sum+TotalMarks,0);
31+
console.log(TotalMark);
32+
33+
//Print even numbers
34+
var scores = [12,13,14,16]
35+
var nscores=[];
36+
for(let i=0;i<scores.length;i++)
37+
{
38+
if(scores[i]%2==0)
39+
nscores.push(scores[i]);
40+
}
41+
console.log(nscores);
42+
43+
//Now lets do the same using filter method
44+
let newFilterScores = scores.filter(score=>score%2==0);
45+
//it is filtering all the element on a certain condition
46+
console.log(newFilterScores);
47+
48+
//Map Array function - - Array multiplied by 3 - [36,42,48]
49+
let newMultArr = newFilterScores.map(score=>score*3);
50+
//it is mapping all the elements by a certain operation
51+
console.log(newMultArr);
52+
let TotalVal = newMultArr.reduce((sum,eachVal)=>sum+eachVal,0); //Now sum them
53+
console.log(TotalVal);
54+
55+
//We can use filter, map, reduce in a sequence also - like below
56+
let finalVal = scores.filter(score=>score%2==0).map(score=>score*3).reduce((sum,eachVal)=>sum+eachVal,0)
57+
console.log(finalVal);
58+
59+
//Sorting an array with Strings
60+
//Sorting an array with Numbers
61+
let fruits = ["banana","kiwi","apple","jamun","papaya"]
62+
fruits.sort();
63+
console.log(fruits);
64+
console.log(fruits.reverse());
65+
66+
var list = [20,13,34,23,45,44,56,102,67,78];
67+
console.log(list.sort()); //This sorts as per the digit value
68+
console.log(list.sort((a,b)=>a-b)); // This is bubble sort
69+
console.log(list.sort((a,b)=>b-a)); // in reverse order
70+
71+
72+
73+
74+
75+
76+
77+
78+
79+
80+
81+

0 commit comments

Comments
(0)

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