This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const students = [ | |
{"name":"shoaib","age":20}, | |
{"name":"alex","age":10}, | |
{"name":"mehedi","age":5}, | |
{"name":"linda","age":12}, | |
{"name":"lilly","age":2}, | |
{"name":"william","age":1}, | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var x = 10; | |
function createFunction1() { | |
var x = 20; | |
return new Function('return x;'); // this |x| refers global |x| | |
} | |
function createFunction2() { | |
var x = 20; | |
function f() { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Simple way | |
const person = { name: "Shoaib", Age: 25, Gender: "Male" }; | |
for (const property in person) { | |
console.log(`${property}: ${person[property]}`); | |
} | |
// Another way | |
const anotherPerson = { | |
Name: 'Shoaib', | |
Age: 25, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// reverse using basic functions | |
function reverse(string) { | |
return string.split("").reverse().join(""); | |
} | |
console.log(reverse('shoaib')); | |
// reverse using loop | |
function reverse(string) { | |
var newString = ""; | |
for (var i = string.length - 1; i >= 0; i--) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const students = [ | |
{name: 'Shoaib', roll: 2}, | |
{name: 'Mehedi', roll: 10}, | |
{name: 'Alex', roll: 5} | |
]; | |
function search(student) { | |
return student.name=== "Mehedi"; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let arrOne = [1,3,5] | |
let arrTwo = [2,4,6] | |
// first way | |
let combine = arrOne.concat(arrTwo) | |
console.log(combine) | |
// second way | |
combine = [...arrOne,...arrTwo] | |
console.log(combine) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// sort alphabetically | |
const name = ['Shoaib', 'Mehedi', 'Alex', 'Jane']; | |
const arr = [1, 30, 4, 21, 100000]; | |
name.sort(); | |
console.log(name); | |
// sort numerically | |
arr.sort(function(a, b) { | |
return a - b; | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function mostRepeated(array){ | |
return array.sort((a,b) => | |
array.filter(v => v===a).length | |
- array.filter(v => v===b).length | |
).pop(); | |
} | |
console.log(mostRepeated(['shoaib', 'alex', 'mehedi', 'alex'])); // apple |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var object = { | |
res: 0, | |
add: function(a, b) { | |
this.res = a + b; | |
return this; | |
}, | |
multiply: function(a) { | |
this.res = this.res * a; | |
return this; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const students = [ | |
{"name":"shoaib","age":20}, | |
{"name":"alex","age":10}, | |
{"name":"mehedi","age":5}, | |
{"name":"linda","age":12}, | |
{"name":"lilly","age":2}, | |
{"name":"william","age":1}, | |
] | |
let filter = students.filter((student)=>{ | |
return student.age <= 10 |
OlderNewer