Skip to content

Instantly share code, notes, and snippets.

@Nalini1998
Nalini1998 / reduce()
Created January 16, 2024 07:50
The reduce() method
This is one of the most powerful JavaScript array methods because it applies a reducer function to each element of your array and returns a single output. The reducer function iterates through all elements in your array from left to right (in order) and returns the result of the previous element’s calculation.
Thus, the final result is a single value. This single value is the function’s accumulated result after executing a reducer function for every array element.
```
// Syntax
myArray.reduce(callbackFn, initialValue)
```
For example:
@Nalini1998
Nalini1998 / map()
Created January 16, 2024 07:48
The map() method
The map() method is used to iterate over an array and modify its elements using a callback function. This callback function will run on each array element and return a new array of modified elements.
```
// Syntax
myArray.map(callbackFn)
myArray.map(function(element, index, array){ /* ... */ })
```
For example:
```
@Nalini1998
Nalini1998 / forEach()
Created January 16, 2024 07:42
The forEach() method
The forEach() method is used to loop through all elements of an array and calls a function (callback function) for each element in the array. The callback function has access to the current element, index, and the entire array on every loop.
```
// Syntax
myArray.forEach(callbackFn)
myArray.forEach(function(element, index, array){ /* ... */ })
```
For example:
@Nalini1998
Nalini1998 / index.html
Created July 28, 2023 16:38
To do App
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
body {
margin: 0;
min-width: 250px;
}
@Nalini1998
Nalini1998 / Setting Status Codes
Created July 19, 2023 09:29
Express allows us to set the status code on responses before they are sent. Response codes provide information to clients about how their requests were handled. Until now, we have been allowing the Express server to set status codes for us. For example, any `res.send()` has by default sent a `200 OK` status code. The res object has a `.status()`…
LEARN EXPRESS ROUTES
Setting Status Codes
Express allows us to set the status code on responses before they are sent. Response codes provide information to clients about how their requests were handled.
Until now, we have been allowing the Express server to set status codes for us. For example, any res.send() has by default sent a 200 OK status code.
The res object has a .status() method to allow us to set the status code, and other methods like .send() can be chained from it.
const monsterStoreInventory = { fenrirs: 4, banshees: 1, jerseyDevils: 4, krakens: 3 };
app.get('/monsters-inventory/:name', (req, res, next) => {
@Nalini1998
Nalini1998 / Athletica Project
Created July 19, 2023 09:27
In this Project, we’ll use the commands we've learned to redirect files in Athletica, a sporting events directory.
### **SOFTWARE ENGINEERING FOUNDATIONS**
# **Project: Athletica**
<br>
# **Tasks**
#### **1. Print the working directory**
```
$ pwd
@Nalini1998
Nalini1998 / Project: Artusi
Created July 19, 2023 09:26
Let's use commands to manipulate the files and directories of Artusi, an arts supply Store
### **WEB DEVELOPMENT**
# **Project: Artusi**
<br>
# **Tasks**
<br>
#### **1. Print the working directory**
@Nalini1998
Nalini1998 / Setup, Exercise, and Verify
Created April 20, 2023 22:10
AUTOMATE AND ORGANIZE TESTS Setup, Exercise, and Verify In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive. The phases are defined as follows: Setup - create objects, variables, and set conditions th…
**Setup, Exercise, and Verify**
- In this exercise you will be separating a test into setup, exercise, and verify phases. This distinct and well-defined separation of steps makes your test more reliable, maintainable, and expressive.
- The phases are defined as follows:
+ Setup - create objects, variables, and set conditions that your test depends on;
+ Exercise - execute the functionality you are testing;
+ Verify - check your expectations against the result of the exercise phase. You can use the assert library here.
@Nalini1998
Nalini1998 / Install Mocha Part II
Created April 20, 2023 18:50
Install Mocha Part II
#How to install Mocha Part II?
1. After installing Mocha as a dependency we can run it in two ways.
+ The first (and more tedious) method is to call it directly from node_modules:
`
$ ./node_modules/mocha/bin/mocha
`
+ The second (and recommended) method is to add a script to package.json. In the scripts object in package.json, set the value of "test" to mocha. It should look like this:
`
@Nalini1998
Nalini1998 / Install Mocha I Part 1
Last active April 20, 2023 22:13
Install Mocha I Part 1
[How to install Mocha Part 1?](https://www.codecademy.com/journeys/full-stack-engineer/paths/fscj-22-front-end-development/tracks/fscj-22-javascript-testing/modules/wdcp-22-write-good-tests-with-mocha-764e85ca-0abf-4da9-91a2-43f8d593eab8/lessons/automate-organize-tests/exercises/install-mocha-i)
1. Before writing any tests you’ll need to use Node.js and npm to set up a JavaScript project and install Mocha;
2. Node allows you to run JavaScript in the terminaL;
3. `npm` is a **Node tool** that allows you to download packages from the web, and manage them in a JavaScript project;
4. Mocha is one of those packages and is used to test other JavaScript code;
5. A JavaScript project is a directory of files. The following command creates a file package.json that can be used to manage packages for the project.
`
$ npm init
`