-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
74085d0
commit 1e5ff84
Showing
9 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
var myJSON = '{ "fname": "Andy", "lname": "Mellon", "age": 46, "city":"Jackson", "state": "NJ" }'; | ||
var myObj = JSON.parse(myJSON); | ||
console.log(myObj.fname + " " + myObj.lname + " is from " + myObj.city + ", " + myObj.state) ; |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<body> | ||
|
||
<h2>Store and retreive data from local storage.</h2> | ||
|
||
<p id="demo"></p> | ||
|
||
<script> | ||
var myObj, myJSON, text, obj; | ||
|
||
//Storing data: | ||
myObj = { "name":"John", "age":31, "city":"New York" }; | ||
myJSON = JSON.stringify(myObj); | ||
localStorage.setItem("testJSON", myJSON); | ||
|
||
//Retrieving data: | ||
text = localStorage.getItem("testJSON"); | ||
obj = JSON.parse(text); | ||
document.getElementById("demo").innerHTML = obj.name; | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
|
||
var myObj, myJSON, text, obj; | ||
//Storing data: | ||
myObj = '{ "fname": "Andy", "lname": "Mellon", "age": 46, "city":"Jackson", "state": "NJ" }'; | ||
myJSON = JSON.stringify(myObj); | ||
localStorage.setItem("testJSON", myJSON); | ||
|
||
//Retrieving data: | ||
text = localStorage.getItem("testJSON"); | ||
obj = JSON.parse(text); | ||
console.log(obj.fname + " " + obj.lname); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
function f(a,b,c) { | ||
// Argument a is re-assigned to a new value. | ||
// The object or primitive referenced by the original a is unchanged. | ||
a = 3; | ||
// Calling b.push changes its properties - it adds | ||
// a new property b[b.length] with the value "foo". | ||
// So the object referenced by b has been changed. | ||
console.log(b[1]); | ||
b[1] = "meany"; | ||
// The "first" property of argument c has been changed. | ||
// So the object referenced by c has been changed (unless c is a primitive) | ||
c.first = false; | ||
} | ||
|
||
var x = 4; | ||
var y = ["eeny", "miny", "mo"]; | ||
var z = {first: true}; | ||
f(x,y,z); | ||
console.log(x, y, z.first); // 4, ["eeny", "miny", "mo", "foo"], false |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function Person(first, last, age, eyeColor, nationality) { | ||
this.firstName = first; | ||
this.lastName = last; | ||
this.age = age; | ||
this.eyeColor = eyeColor; | ||
this.nationality = nationality; | ||
this.name = function() { | ||
return this.firstName + " " + this.lastName; } | ||
} | ||
|
||
var myFather = new Person("James", "Mellon",70, "Brown", "English"); | ||
var myMother = new Person("Diane", "Mellon",70, "Brown", "German"); | ||
|
||
console.log(myFather.name()); | ||
console.log("is " + myFather.nationality); | ||
var test = ("a" == false)? "true": "false"; | ||
console.log("Test result is " + test); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
function abc() { console.log("Hello World")}(); | ||
|
||
|
||
function Point(x_pt,y_pt,z_pt,name) { | ||
this.x = x_pt; | ||
this.y = y_pt; | ||
this.z = z_pt; | ||
this.pt_name = name; | ||
this.dist = function(input) { | ||
var x1 = this.x - input.x; | ||
var y1 = this.y - input.y; | ||
var z1 = this.z - input.z; | ||
return x1 + y1 + z1; | ||
} | ||
} | ||
|
||
var myOrigin = new Point(0,0,0,"origin"); | ||
var my2ndPt = new Point(10,20,10,"2nd Pt"); | ||
console.log("the distance between pts is " +myOrigin.dist(my2ndPt)); | ||
abc(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
|
||
var x = [ 1,2,3,4,5,6,7]; | ||
var x2 = []; | ||
var y, y_end; | ||
|
||
var interations = 1000000; | ||
console.time("For loop"); | ||
for(var i = 0; i < x.length; i++) | ||
{ | ||
console.log(x[i]*x[i]); | ||
} | ||
console.timeEnd("For loop"); | ||
//y_end = performance.now(); | ||
|
||
|
||
console.time("Foreach loop"); | ||
x.forEach(function (a) { | ||
console.log(a*a); | ||
}); | ||
console.timeEnd("Foreach loop"); | ||
|
||
console.time("Map loop"); | ||
x.map(function (a) { | ||
console.log(a*a); | ||
}); | ||
console.timeEnd("Map loop"); | ||
|
||
//var y_end = performance.now(); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
a = [1,2,3,4,5,6,7]; | ||
|
||
function doSomething() { | ||
for (var x=0; x < a.length; x++) | ||
console.log(a[x]*a[x]) | ||
} | ||
|
||
function doSomethingFast() { | ||
a.forEach(function(x) { | ||
console.log(x*x); }); | ||
} | ||
|
||
function doSomethingFaster() { | ||
a.map(function(x) { | ||
console.log(x*x); | ||
}); | ||
} | ||
|
||
|
||
console.time("Do Something"); | ||
doSomething(); | ||
console.timeEnd("Do Something"); | ||
|
||
console.time("Do SomethingFast"); | ||
doSomethingFast(); | ||
console.timeEnd("Do SomethingFast"); | ||
|
||
console.time("Do Something Faster"); | ||
doSomethingFaster(); | ||
console.timeEnd("Do Something Faster"); |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
console.log('hi'); | ||
setTimeout(function() { console.log('my name is '); | ||
}, 5000); | ||
console.log("zayan"); |