-
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(i18n,learn): processed translations
- Loading branch information
Showing
207 changed files
with
7,641 additions
and
392 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
212 changes: 212 additions & 0 deletions
212
...bic/25-front-end-development/lab-depth-first-search/587d825d367417b2b2512c96.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,212 @@ | ||
--- | ||
id: 587d825d367417b2b2512c96 | ||
title: Implement the Depth-First Search Algorithm | ||
challengeType: 14 | ||
dashedName: implement-the-depth-first-search-algorithm | ||
--- | ||
|
||
# --description-- | ||
|
||
<dfn>Depth-first search</dfn> (DFS) is an algorithm used to search through data structures such as trees or graphs. Starting from a root node, the search first goes down a path of edges as far as it can. Once it reaches one end of a path, the search will backtrack to the last node with an unvisited edge path and continue searching down the unvisited edge path. | ||
|
||
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab. | ||
|
||
**User Stories:** | ||
|
||
1. You should write a function `dfs()` that implements the <dfn>depth-first search</dfn> algorithm on a graph. | ||
1. The function should keep track of the visited nodes. | ||
1. The function should use a stack, an array where the last element added is the first to be removed, to make sure to visit the neighbors of the most recently added node. | ||
1. The function should take an undirected, adjacency matrix `graph` and a node label `root` as parameters. The node label is the numeric value of the node between `0` and `n - 1`, where `n` is the total number of nodes in the graph. | ||
1. The function should output an array of all nodes reachable from `root`. | ||
|
||
# --hints-- | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` with a start node of `1` should return an array with `0`, `1`, `2`, and `3`. | ||
|
||
```js | ||
assert.sameMembers( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 1); | ||
})(), | ||
[0, 1, 2, 3] | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` with a start node of `3` should return an array with `3`, `2`, `1`, and `0`. | ||
|
||
```js | ||
assert.sameMembers( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 3); | ||
})(), | ||
[3, 2, 1, 0] | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 1], [0, 0, 1, 0]]` with a start node of `1` should return an array with four elements. | ||
|
||
```js | ||
assert( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 1); | ||
})().length === 4 | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` with a start node of `3` should return an array with `3`. | ||
|
||
```js | ||
assert.sameMembers( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 0], | ||
[0, 0, 0, 0] | ||
]; | ||
return dfs(graph, 3); | ||
})(), | ||
[3] | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 1, 0], [0, 1, 0, 0], [0, 0, 0, 0]]` with a start node of `3` should return an array with one element. | ||
|
||
```js | ||
assert( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 0], | ||
[0, 0, 0, 0] | ||
]; | ||
return dfs(graph, 3); | ||
})().length === 1 | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]` with a start node of `3` should return an array with `2` and `3`. | ||
|
||
```js | ||
assert.sameMembers( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 0, 0], | ||
[0, 0, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 3); | ||
})(), | ||
[2, 3] | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]` with a start node of `3` should return an array with two elements. | ||
|
||
```js | ||
assert( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 0, 0], | ||
[0, 0, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 3); | ||
})().length === 2 | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]` with a start node of `0` should return an array with `0` and `1`. | ||
|
||
```js | ||
assert.sameMembers( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 0, 0], | ||
[0, 0, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 0); | ||
})(), | ||
[0, 1] | ||
); | ||
``` | ||
|
||
The input graph `[[0, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 1], [0, 0, 1, 0]]` with a start node of `0` should return an array with two elements. | ||
|
||
```js | ||
assert( | ||
(function () { | ||
var graph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 0, 0], | ||
[0, 0, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
return dfs(graph, 0); | ||
})().length === 2 | ||
); | ||
``` | ||
|
||
# --seed-- | ||
|
||
## --seed-contents-- | ||
|
||
```js | ||
|
||
``` | ||
|
||
# --solutions-- | ||
|
||
```js | ||
function dfs(graph, root) { | ||
const stack = []; | ||
let tempV; | ||
const visited = []; | ||
let tempVNeighbors = []; | ||
stack.push(root); | ||
while (stack.length > 0) { | ||
tempV = stack.pop(); | ||
if (visited.indexOf(tempV) == -1) { | ||
visited.push(tempV); | ||
tempVNeighbors = graph[tempV]; | ||
for (let i = 0; i < tempVNeighbors.length; i++) { | ||
if (tempVNeighbors[i] == 1) { | ||
stack.push(i); | ||
} | ||
} | ||
} | ||
} | ||
return visited; | ||
} | ||
|
||
const exDFSGraph = [ | ||
[0, 1, 0, 0], | ||
[1, 0, 1, 0], | ||
[0, 1, 0, 1], | ||
[0, 0, 1, 0] | ||
]; | ||
console.log(dfs(exDFSGraph, 0)); | ||
``` |
76 changes: 76 additions & 0 deletions
76
...ront-end-development/lab-file-metadata-microservice/bd7158d8c443edefaeb5bd0f.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
--- | ||
id: bd7158d8c443edefaeb5bd0f | ||
title: File Metadata Microservice | ||
challengeType: 4 | ||
dashedName: file-metadata-microservice | ||
--- | ||
|
||
# --description-- | ||
|
||
Build a full stack JavaScript app that is functionally similar to this: <a href="https://file-metadata-microservice.freecodecamp.rocks" target="_blank" rel="noopener noreferrer nofollow">https://file-metadata-microservice.freecodecamp.rocks</a>. Working on this lab will involve you writing your code using one of the following methods: | ||
|
||
- Clone <a href="https://github.com/freeCodeCamp/boilerplate-project-filemetadata/" target="_blank" rel="noopener noreferrer nofollow">this GitHub repo</a> and complete your project locally. | ||
- Use <a href="https://gitpod.io/?autostart=true#https://github.com/freeCodeCamp/boilerplate-project-filemetadata/" target="_blank" rel="noopener noreferrer nofollow">our Gitpod starter project</a> to complete your project. | ||
- Use a site builder of your choice to complete the project. Be sure to incorporate all the files from our GitHub repo. | ||
|
||
# --instructions-- | ||
|
||
**HINT:** You can use the `multer` npm package to handle file uploading. | ||
|
||
# --hints-- | ||
|
||
You should provide your own project, not the example URL. | ||
|
||
```js | ||
(getUserInput) => { | ||
assert( | ||
!/.*\/file-metadata-microservice\.freecodecamp\.rocks/.test( | ||
getUserInput('url') | ||
) | ||
); | ||
}; | ||
``` | ||
|
||
You can submit a form that includes a file upload. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const site = await fetch(getUserInput('url')); | ||
const data = await site.text(); | ||
const doc = new DOMParser().parseFromString(data, 'text/html'); | ||
assert(doc.querySelector('input[type="file"]')); | ||
}; | ||
``` | ||
|
||
The form file input field has the `name` attribute set to `upfile`. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const site = await fetch(getUserInput('url')); | ||
const data = await site.text(); | ||
const doc = new DOMParser().parseFromString(data, 'text/html'); | ||
assert(doc.querySelector('input[name="upfile"]')); | ||
}; | ||
``` | ||
|
||
When you submit a file, you receive the file `name`, `type`, and `size` in bytes within the JSON response. | ||
|
||
```js | ||
async (getUserInput) => { | ||
const formData = new FormData(); | ||
const fileData = await fetch( | ||
'https://cdn.freecodecamp.org/weather-icons/01d.png' | ||
); | ||
const file = await fileData.blob(); | ||
formData.append('upfile', file, 'icon'); | ||
const data = await fetch(getUserInput('url') + '/api/fileanalyse', { | ||
method: 'POST', | ||
body: formData | ||
}); | ||
const parsed = await data.json(); | ||
assert.property(parsed, 'size'); | ||
assert.equal(parsed.name, 'icon'); | ||
assert.equal(parsed.type, 'image/png'); | ||
}; | ||
``` | ||
|
Oops, something went wrong.