mirror of
https://github.com/caperren/school_archives.git
synced 2025-11-09 21:51:15 +00:00
Added work from my other class repositories before deletion
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<title>title</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="javascript_objects.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,33 @@
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Call a function before it's declared
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
//Function call and console logging BEFORE function decleration
|
||||
console.log(simple_string_reverser("Here is some text to reverse!")); //Workss
|
||||
|
||||
function simple_string_reverser(input_word) {
|
||||
if(typeof(input_word) != 'string'){
|
||||
console.log("Error. Wrong input type.");
|
||||
return;
|
||||
}
|
||||
|
||||
var new_simple_string = "";
|
||||
var input_length = input_word.length;
|
||||
for(var i = 0 ; i < input_word.length ; i++) {
|
||||
new_simple_string += input_word[input_length-1-i];
|
||||
}
|
||||
return new_simple_string;
|
||||
}
|
||||
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
// Call a function assigned to a variable before it's declared
|
||||
//////////////////////////////////////////////////////////////////////
|
||||
|
||||
console.log(one_year_ago_date_string()); //Doesn't work
|
||||
|
||||
var one_year_ago_date_string = function(){
|
||||
var temp_date = new Date();
|
||||
temp_date.setFullYear(temp_date.getFullYear()-1);
|
||||
return temp_date.toDateString();
|
||||
}
|
||||
console.log(one_year_ago_date_string()); //Works
|
||||
@@ -0,0 +1,45 @@
|
||||
function deepEqual(a, b){
|
||||
if(((typeof(a) === 'object') && (a !== null)) &&
|
||||
((typeof(b) === 'object') && (b !== null))){
|
||||
|
||||
var size_a = 0;
|
||||
var size_b = 0;
|
||||
|
||||
for(prop in a){ size_a++; }
|
||||
|
||||
for(prop in b){ size_b++; }
|
||||
|
||||
if(size_a == size_b){
|
||||
for(prop in a){
|
||||
if(!b.hasOwnProperty(prop)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for(prop in a){
|
||||
if(!deepEqual(a[prop], b[prop])){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
|
||||
}else{
|
||||
return (a === b);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
var obj = {here: {is: "an"}, object: 2};
|
||||
console.log(deepEqual(obj, obj));
|
||||
|
||||
console.log(deepEqual(obj, {here: 1, asd: 2}));
|
||||
|
||||
console.log(deepEqual(obj, {here: {is: "an"}, object: 2}));
|
||||
|
||||
//console.log(deepEqual(1, 2));
|
||||
|
||||
//console.log(deepEqual(2, 2));
|
||||
Reference in New Issue
Block a user