Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ <h3>Objects</h3>
<img src="http://memecrunch.com/meme/MQ7A/lolcat-i-object/image.jpg">

<script src="main.js"></script>
<script src="challenge.js"></script>
<script src="warmup.js"></script>
</body>
</html>
224 changes: 224 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
var names =
{
firstName: "Josh",
lastname: "Lehman"
};
var num =
{
a: 1,
b:2,
c: 3,
d: 4
};
var animals =
{
animal: "dog",
noise: "bark",
age: 3,
type: "Labrador",
color: "Yellow"
};

var boss =
{
first: "Abhishek",
last: "Bhardwaj",
middle: "Boss",
age: 81,
homeTown: "Meerut",
occupation: "Chilling",
dateOfBirth: 01/23/1945,
pet: "Dog",
favColor: "black"

}

var favMovie =
{
Title:"The Godfather",
Year:"1972",
Rated:"R",
Released :"24 Mar 1972",
Runtime:"175 min",
Genre: ["Crime", "Drama"],
Director: "Francis Ford Coppola",
Writer: ["Mario Puzo (screenplay)", "Francis Ford Coppola (screenplay)", "Mario Puzo (novel)"],
Actors: ["Marlon Brando", "Al Pacino", "James Caan", "Richard S. Castellano"],
Plot:"The aging patriarch of an organized crime dynasty transfers control of his clandestine empire to his reluctant son.",
Language: ["English", "Italian", "Latin"],
Country:"USA",
Awards:"Won 3 Oscars. Another 23 wins & 27 nominations.",
Poster:"http://ia.media-imdb.com/images/M/MV5BMjEyMjcyNDI4MF5BMl5BanBnXkFtZTcwMDA5Mzg3OA@@._V1_SX300.jpg",
Metascore:"100",
imdbRating:"9.2",
imdbVotes:"1,131,262",
imdbID:"tt0068646",
Type:"movie",
Response:"True"
}

var key = "name";
var person = {
name: "Alyssa P. Hacker",
age: 26,
hometown: "somewhere"
};
// person[age]; // => 26
// person.key; // => "Alyssa P. Hacker"
// person["somewhere"] // => ???

function formatName(boss)
{
return boss.first + " " + boss.last;
};

var people = [
{name: {first: "Alyssa", middle: "P.", last: "Hacker"}, age: 26},
{name: {first: "Ben", last: "Bitdiddle"}, age: 34},
{name: {first: "Eva", middle: "Lu", last: "Ator"}, age: 40},
{name: {first: "Lem", middle: "E.", last: "Tweakit"}, age: 45},
{name: {first: "Louis", last: "Reasoner"}, age: 21},
{name: {first: "Louis", last: "Reasoner"}, age: 31}

];


function fullName(people)
{ var fullnames = [];
for(i=0; i < people.length; i++)
{
fullnames.push(formatName(people[i].name));
}

return fullnames;
}

function average(people)
{
var sum = 0;
for(i=0; i < people.length; i++)
{
sum = sum + people[i].age ;
}

return (sum/people.length).toFixed(2);
}

function ageGreater(people,age)
{
var agegreater = [];
for(i=0; i < people.length; i++)
{
if(age < people[i].age)
{
agegreater.push(formatName(people[i].name));
}

}

if(agegreater.length > 0)
{
return agegreater;
}
else
{
return "No Result !!"
}
}


var dirtyObject = {
_fht: 192492,
name: "Alyssa P. Hacker",
age: 26,
_byz: 939205,
_ttrs: 510852
}

function clean(obj) {
// ...
var clean = {};
for(var key in obj)
{
if(key.charAt(0) === " ")
{
delete obj[key];
}
}

return obj;
}
//clean(dirtyObject); // => {name: "Alyssa P. Hacker", age: 26}

function removesOddValues(obj)
{
for(var key in obj)
{
if(typeof(obj[key] === "number"))
{
if(obj[key] % 2 === 1)
{
delete obj[key];
}
}
}

return obj;
}

function countWords(s)
{
var words = s.split(" ");
var obj = {};
for(var i=0; i < words.length; i++)
{
var lwords = words[i].toLowerCase();
if(obj[lwords] === undefined){
obj[lwords] = 1;
}
else
{
obj[lwords] = obj[lwords] + 1;
}
}


return obj;
}

function countCharacters(s)
{
var words = s.split("");
var obj = {};
for(var i=0; i < words.length; i++)
{
var lwords = words[i].toLowerCase();
if(obj[lwords] === undefined){
obj[lwords] = 1;
}
else
{
obj[lwords] = obj[lwords] + 1;
}
}

clean(obj);

return obj;
}

// function select(obj,keys)
// {
// var newobj = {};
// for(i=0; i < keys.length; i++)
// {
// newobj
// }
// for(var key in obj)
// {
// if(key === )
// }
// }



123 changes: 123 additions & 0 deletions warmup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
var number = [2,1,2,3,1,1,2]

//takes in an array and a value to be removed
function remove(array,num){

for(var i = 0; i < array.length; i++){
//checking to see if the value at teh current index
// is equal the item to be removed
if(array[i] === num)
{
array.splice(i,1);
// however splice will skip over the next duplicate
// if they are continous// we decrement by one to keep the index what it is before it entererd the check
i--;
}
}

return array;
}


function min(array){

var min = number.POSITIVE_INFINITY;

for(var i = 0; i < array.length; i++)
{
if(array[i] < min)
{
min = array[i]
}
}
return min;
}


//Write a function squareAll that takes an array of numbers as a parameter and returns a new array of the input numbers squared

function sqaureAll(array)
{
var newarray = [];
for(i = 0; i < array.length; i++)
{
newarray.push(array[i]*array[i]);
}

return newarray;
}


//Write a function addArrays that takes 2 arrays of numbers as parameters and returns a new array where
//elements at same index position are added together. For example: addArrays([1,2,3], [4,3,2,1]); // => [5,5,5,1]

function addArrays(array1,array2)
{
var newarray = [];

// if array.lenth is equal // just add them
if(array1.length == array2.length)
{
for(i = 0 ; i < array1.length; i++)
{
newarray.push(array1[i] + array2[i]);
}
}
else if(array1.length != array2.length) //check if the array.length is not equal
{
if(array1.length > array2.length) // check which array is greater
{
for(i=0; i < array2.length; i++) // loop through the smaller array and add arrays
{
var array1left = array1.length - array2.length; // check the difference between the array
newarray.push(array1[i] + array2[i]);

}
for(j=0; j < array1left; j++)
{
newarray.push(array1[array2.length+j]); //
//array1.pop();
}
}
else
{
for(i=0; i < array1.length; i++)
{
var array2left = array2.length - array1.length;
newarray.push(array1[i] + array2[i]);

}
for(k=0 ; k < array2left; k++)
{
newarray.push(array2[array1.length+k]);
//array2.pop();
}
}
}

return newarray;

}

// do it recurrsion



function addArray(arr1, arr2) {
var arrNew = [];
if(arr1.length === arr2.length) {
for(var i = 0; i<arr1.length; i++) {
arrNew.push(arr1[i] + arr2[i]);
}

return arrNew;
}
else if(arr1.length < arr2.length) {
arr1.push(0);
return addArray(arr1, arr2);
}
else if(arr2.length < arr1.length) {
arr2.push(0);
return addArray(arr1, arr2);
}
}