Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
abid-siddiqui authored Mar 22, 2017
1 parent 74085d0 commit 1e5ff84
Show file tree
Hide file tree
Showing 9 changed files with 156 additions and 0 deletions.
3 changes: 3 additions & 0 deletions JSON_input.js
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) ;
24 changes: 24 additions & 0 deletions JSON_local.htm
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>
11 changes: 11 additions & 0 deletions JSON_localstorage.js
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);
19 changes: 19 additions & 0 deletions JS_byRef_byVal.js
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
17 changes: 17 additions & 0 deletions PersonObjectProto.js
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);
20 changes: 20 additions & 0 deletions Point_prototype.js
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();
28 changes: 28 additions & 0 deletions Squares.js
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();
30 changes: 30 additions & 0 deletions TimeTest.js
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");
4 changes: 4 additions & 0 deletions test.js
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");

0 comments on commit 1e5ff84

Please sign in to comment.