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
95 changes: 67 additions & 28 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ function myFunction() {
myFunction();

//🚀🚀🚀 ⬇️ 📝 Explanation ⬇️ 📝 🚀🚀🚀:

//nestedFunction() is able to access var internal becuase of the closure fmred between nestedFunction() and the higher order function myFunction().



Expand All @@ -28,11 +28,16 @@ myFunction();

For example, `summation(4)` should return 10 because 1+2+3+4 is 10. Note, you may use a for loop for this function if you wish */

function summation(/*Your Code Here*/) {
/*Your Code Here*/

function summation(number){
let sum = 0;
for(let i = 0; i < number + 1; i++){
sum += i;
}

return sum;
}


console.log('task 2', summation(4));

// 🦁🦁🦁 Topic 2: ADVANCED Array Methods 🦁🦁🦁
// Given this zoo data from around the United States, follow the instructions below. Use the specific array methods in the requests below to solve the problems.
Expand All @@ -56,8 +61,14 @@ const zooAnimals = [
displayNames will be an array of strings, and each string should follow this pattern: "name: {name}, scientific: {scientific name}"
*/

function animalNames(/*Your Code Here*/){
/*Your Code Here*/


function animalNames(array){
const displayNames = [];
array.forEach(function(item, index){
displayNames.push(`name: ${item.animal_name}, scientific: ${item.scientific_name}`);
});
return displayNames;
}


Expand All @@ -67,29 +78,39 @@ const zooAnimals = [
For example: ['jackal, asiatic', .....]
*/

function lowerCaseNames(/*Your Code Here*/){
/*Your Code Here*/
function lowerCaseNames(array){
const lowerCase = [];
array.map(function(item){
lowerCase.push(item.animal_name.toLowerCase());
});
return lowerCase;
}


/* 🦁🦁🦁 Request 3: .filter() 🦁🦁🦁
The zoo is concerned about animals with a lower population count.
Using lowPopulationAnimals use .filter() to create a new array of objects which contains only the animals with a population of less than 5.
*/

function lowPopulationAnimals(/*Your Code Here*/){
/*Your Code Here*/
function lowPopulationAnimals(array){
array.filter(function(item){
return item.population < 5;
});
return array;
}


/* 🦁🦁🦁 Request 4: .reduce() 🦁🦁🦁
The zoo needs to know their total animal population across the United States.
Using USApop find the total population from the zoos array using the .reduce() method.
Remember the reduce method takes two arguments: a callback (which itself takes two args - the accumulator and the item), and an initial value for the count.
*/

function USApop(/*Your Code Here*/){
/*Your Code Here*/
function USApop(array){
const sum = array.reduce(function(acc, item){
return acc + item.population;
}, 0);
return sum;
}


Expand All @@ -101,30 +122,30 @@ const zooAnimals = [
* The consume function should return the invocation of cb, passing a and b into cb as arguments
*/

function consume(/*Your Code Here */){
/*Your Code Here */
function consume(a,b,cb){
return cb(a,b);
}


/* 🦁🦁🦁 Step 2: Create several functions to callback with consume(); 🦁🦁🦁 */
// 🦁🦁🦁 Use add to return the sum of two numbers 🦁🦁🦁

function add(/*Your Code Here */){
/*Your Code Here*/
function add(a,b){
return a + b;
}


// 🦁🦁🦁 Use multiply to return the product of two numbers 🦁🦁🦁

function multiply(/*Your Code Here */){
/*Your Code Here */
function multiply(a,b){
return a * b;
}


// 🦁🦁🦁 Use greeting to accept a first and last name and return "Hello {first-name} {last-name}, nice to meet you!" 🦁🦁🦁

function greeting(/*Your Code Here */){
return /*Your Code Here */
function greeting(first, last){
return `Hello ${first} ${last}, nice to meet you!`
}


Expand All @@ -139,8 +160,10 @@ function greeting(/*Your Code Here */){
/* 🐴🐴🐴 Step 1: Base Constructor 🐴🐴🐴
Use the constructor function named CuboidMaker to accept properties for length, width, and height which can be initialized as an object
*/
function CuboidMaker(/*Your Code Here */){
/*Your Code Here */
function CuboidMaker(obj){
this.length = obj.length;
this.width = obj.width;
this.height = obj.height;
}


Expand All @@ -149,6 +172,9 @@ function CuboidMaker(/*Your Code Here */){
Formula for cuboid volume: length * width * height */


CuboidMaker.prototype.volume = function(){
return this.height*this.length*this.height;
}



Expand All @@ -157,7 +183,9 @@ function CuboidMaker(/*Your Code Here */){
Formula for cuboid surface area of a cube:
2 * (length * width + length * height + width * height) */


CuboidMaker.prototype.surfaceArea = function(){
return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
}



Expand All @@ -166,7 +194,7 @@ function CuboidMaker(/*Your Code Here */){
Add properties and values of length: 4, width: 5, and height: 5 to cuboid. */



const cuboid = new CuboidMaker({length: 4, width: 5, height: 5});


// 🐴🐴🐴 Test your volume and surfaceArea methods by uncommenting the logs below: 🐴🐴🐴
Expand All @@ -178,9 +206,20 @@ function CuboidMaker(/*Your Code Here */){
// 🦄🦄🦄 Topic 4: Classes 🦄🦄🦄 //
//🦄🦄🦄 1. Take your prototypes from above and refactor into class syntax. Please rename your class CuboidMakerTwo and your object cuboidTwo 🦄🦄🦄
class CuboidMakerTwo{

constructor(atr){
this.length = atr.length;
this.width = atr.width;
this.height = atr.height;
}
volume(){
return this.height*this.length*this.height;
}
surfaceArea(){
return 2 * (this.length * this.width + this.length * this.height + this.width * this.height);
}
}

const cuboidTwo = new CuboidMaker({length: 4, width: 5, height: 5});

//🦄🦄🦄 Test your volume and surfaceArea methods by uncommenting the logs below: 🦄🦄🦄
// console.log(cuboidTwo.volume()); // 100
Expand Down
Loading