Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

answer 10 qns #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
19 changes: 19 additions & 0 deletions js/q1.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// 1.) Find the last name in the following array:

// js
var friends = [
'Moe',
'Larry',
'Curly',
'Jane',
'Emma',
'Elizabeth',
'Elinor',
'Mary',
'Darcy',
'Grey',
'Lydia',
'Harriet'
];

console.log(friends[friends.length-1])
15 changes: 15 additions & 0 deletions js/q10.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@

var ages = [83, 53, 37, 29, 60, 30, 66, 19, 59, 41, 9, 64, 19, 80, 24, 53, 70, 1, 53, 40, 92, 4, 71, 65, 8, 2, 51, 80, 94, 37, 80, 64, 19, 6, 14];


var sortAges = ages.sort(function(a, b) {
return a - b;
});

// console.log(sortAges)

var totalNum = sortAges.length;
var medianIndex = ((totalNum +1) / 2) - 1;

// console.log(totalNum);
console.log('Median age is ' + sortAges[medianIndex]);
16 changes: 16 additions & 0 deletions js/q2.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var friends = [
'Moe',
'Larry',
'Curly',
'Jane',
'Emma',
'Elizabeth',
'Elinor',
'Mary',
'Darcy',
'Grey',
'Lydia',
'Harriet'
];

console.log(friends.sort());
3 changes: 3 additions & 0 deletions js/q3.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet';

console.log(friends.split(',').sort().join(','))
3 changes: 3 additions & 0 deletions js/q4.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
var friends = 'Moe,Larry,Curly,Jane,Emma,Elizabeth,Elinor,Mary,Darcy,Grey,Lydia,Harriet';

console.log(friends.split(',').sort().reverse().join(','))
28 changes: 28 additions & 0 deletions js/q5.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@

var myFriends = [
'Rickon',
'Meera',
'Hodor',
'Jojen',
'Osha',
'Rickard',
'Maester',
'Rodrik',
'Jory',
'Septa',
'Jon'
];

var yourFriends = [
'Bilbo',
'Boromir',
'Elrond',
'Faramir',
'Frodo',
'Gandalf',
'Legolas',
'Pippin'
];

var allFriends = myFriends.concat(yourFriends);
console.log(allFriends.sort());
24 changes: 24 additions & 0 deletions js/q6.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

var foods = [
'Popcorn',
'Potato chips',
'Shrimp',
'Chicken rice',
'Poutine',
'Tacos',
'Toast',
'French Toast',
'Crab',
'Pho',
'Lasagna',
'Brownie',
'Lobster',
'Donuts',
'Ice cream',
'Hamburger',
'Sushi',
'Chocolate',
'Pizza'
];

console.log(foods.indexOf('Pho')+1);
26 changes: 26 additions & 0 deletions js/q7.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@


var foods = [
'Popcorn',
'Potato chips',
'Shrimp',
'Chicken rice',
'Poutine',
'Tacos',
'Toast',
'French Toast',
'Crab',
'Pho',
'Lasagna',
'Brownie',
'Lobster',
'Donuts',
'Ice cream',
'Hamburger',
'Sushi',
'Chocolate',
'Pizza'
];

console.log(foods.splice(foods.indexOf('Donuts'), 1));
console.log(foods);
23 changes: 23 additions & 0 deletions js/q8.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
var foods = [
'Popcorn',
'Potato chips',
'Shrimp',
'Chicken rice',
'Poutine',
'Tacos',
'Toast',
'French Toast',
'Crab',
'Pho',
'Lasagna',
'Brownie',
'Lobster',
'Donuts',
'Ice cream',
'Hamburger',
'Sushi',
'Chocolate',
'Pizza'
];

console.log(foods[5-1], foods[10-1]);
16 changes: 16 additions & 0 deletions js/q9.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var nameAge = {
Moe: 18,
Larry: 19,
Curly: 20,
Jane: 20,
Emma: 21,
Elizabeth: 18,
Elinor: 23,
Mary: 25,
Darcy: 24,
Grey: 18,
Lydia: 24,
Harriet: 18
}

console.log(nameAge);
Loading