Skip to content

Commit 778a97b

Browse files
committed
Batman! (this commit has no parents)
0 parents  commit 778a97b

8 files changed

Lines changed: 277 additions & 0 deletions

File tree

.github/worflows/mail.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name: Zero and one parents problem
2+
3+
on: [pull_request]
4+
5+
jobs:
6+
build:
7+
8+
runs-on: ubuntu-latest
9+
10+
steps:
11+
- uses: actions/checkout@v1
12+
- name: Run Jest
13+
uses: stefanoeb/jest-action@1.0.2

.gitignore

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
lerna-debug.log*
8+
9+
# Diagnostic reports (https://nodejs.org/api/report.html)
10+
report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json
11+
12+
# Runtime data
13+
pids
14+
*.pid
15+
*.seed
16+
*.pid.lock
17+
18+
# Directory for instrumented libs generated by jscoverage/JSCover
19+
lib-cov
20+
21+
# Coverage directory used by tools like istanbul
22+
coverage
23+
*.lcov
24+
25+
# nyc test coverage
26+
.nyc_output
27+
28+
# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files)
29+
.grunt
30+
31+
# Bower dependency directory (https://bower.io/)
32+
bower_components
33+
34+
# node-waf configuration
35+
.lock-wscript
36+
37+
# Compiled binary addons (https://nodejs.org/api/addons.html)
38+
build/Release
39+
40+
# Dependency directories
41+
node_modules/
42+
jspm_packages/
43+
44+
# TypeScript v1 declaration files
45+
typings/
46+
47+
# TypeScript cache
48+
*.tsbuildinfo
49+
50+
# Optional npm cache directory
51+
.npm
52+
53+
# Optional eslint cache
54+
.eslintcache
55+
56+
# Microbundle cache
57+
.rpt2_cache/
58+
.rts2_cache_cjs/
59+
.rts2_cache_es/
60+
.rts2_cache_umd/
61+
62+
# Optional REPL history
63+
.node_repl_history
64+
65+
# Output of 'npm pack'
66+
*.tgz
67+
68+
# Yarn Integrity file
69+
.yarn-integrity
70+
71+
# dotenv environment variables file
72+
.env
73+
.env.test
74+
75+
# parcel-bundler cache (https://parceljs.org/)
76+
.cache
77+
78+
# Next.js build output
79+
.next
80+
81+
# Nuxt.js build / generate output
82+
.nuxt
83+
dist
84+
85+
# Gatsby files
86+
.cache/
87+
# Comment in the public line in if your project uses Gatsby and *not* Next.js
88+
# https://nextjs.org/blog/next-9-1#public-directory-support
89+
# public
90+
91+
# vuepress build output
92+
.vuepress/dist
93+
94+
# Serverless directories
95+
.serverless/
96+
97+
# FuseBox cache
98+
.fusebox/
99+
100+
# DynamoDB Local files
101+
.dynamodb/
102+
103+
# TernJS port file
104+
.tern-port

.huskyrc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"hooks": {
3+
"pre-commit": "npm test"
4+
}
5+
}

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 Héctor Olvera Vital
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# challenge-javascript-11 - Zero and one parents problem
2+
3+
Suppose we have some input data describing a graph of relationships between parents and children over multiple generations. The data is formatted as a list of (parent, child) pairs, where each individual is assigned a unique integer identifier.
4+
5+
### Example
6+
7+
In this diagram, 3 is a child of 1 and 2, and 5 is a child of 4:
8+
9+
```md
10+
1 2 4
11+
\ / / | \
12+
3 5 8 9
13+
\ / \ \
14+
6 7 11
15+
```
16+
17+
Example input:
18+
19+
```js
20+
parentChildPairs = [
21+
[1, 3], [2, 3], [3, 6], [5, 6],
22+
[5, 7], [4, 5], [4, 8], [4, 9], [9, 11]
23+
]
24+
```
25+
26+
## Installation
27+
28+
```bash
29+
npm install
30+
```
31+
32+
## Test
33+
34+
```bash
35+
npm run test
36+
```
37+
38+
## Challenge
39+
40+
Write a function that takes this data as input and returns two collections: one containing all individuals with zero known parents, and one containing all individuals with exactly one known parent.
41+
42+
Example output:
43+
44+
```js
45+
[
46+
[1, 2, 4], // Individuals with zero parents
47+
[5, 7, 8, 9, 11] // Individuals with exactly one parent
48+
]
49+
```
50+
51+
## Submit challenge solution
52+
53+
You must "Fork" this project, solve the problem and create a Pull Request to this repository.
54+
55+
## Contribute
56+
57+
If someone wants to add or improve something, I invite them to collaborate directly in this repository: challenge-javascript-11
58+
59+
# License
60+
challenge-javascript-11 is released under the MIT license.

package.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
{
2+
"name": "challenge-javascript-11",
3+
"version": "1.0.0",
4+
"description": "Zero and one parents problem",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "jest"
8+
},
9+
"repository": {
10+
"type": "git",
11+
"url": "git+https://github.com/PlatziMaster/challenge-javascript-11.git"
12+
},
13+
"keywords": [
14+
"JavaScript"
15+
],
16+
"author": "Hector Olvera Vital <hector.olvera@ciencias.unam.mx>",
17+
"license": "MIT",
18+
"bugs": {
19+
"url": "https://github.com/PlatziMaster/challenge-javascript-11/issues"
20+
},
21+
"homepage": "https://github.com/PlatziMaster/challenge-javascript-11#readme",
22+
"devDependencies": {
23+
"husky": "^4.2.3",
24+
"jest": "^25.2.7"
25+
},
26+
"jest": {
27+
"verbose": true,
28+
"transformIgnorePatterns": [
29+
"<rootDir>/(node_modules)/"
30+
]
31+
}
32+
}

src/_test_/index.test.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
const findNodesWithZeroAndOneParents = require("../index");
2+
3+
describe('ZeroAndOneParents', () => {
4+
it('Should returns two collections ', () => {
5+
expect(findNodesWithZeroAndOneParents([
6+
[1, 3], [2, 3], [3, 6], [5, 6], [5, 7],
7+
[4, 5], [4, 8], [4, 9], [9, 11]
8+
]).length).toBe(2);
9+
expect(findNodesWithZeroAndOneParents([
10+
[1, 6], [1, 7], [1, 7], [2, 6], [2, 7], [3, 2], [3, 4],
11+
[4, 8], [5, 8], [6, 9], [6, 10], [7, 11], [8, 11], [8, 12]
12+
]).length).toBe(2)
13+
})
14+
15+
it('Should returns two collections ', () => {
16+
expect(findNodesWithZeroAndOneParents([
17+
[1, 3], [2, 3], [3, 6], [5, 6], [5, 7],
18+
[4, 5], [4, 8], [4, 9], [9, 11]
19+
])).toEqual([
20+
[1, 2, 4],
21+
[5, 7, 8, 9, 11]
22+
]);
23+
24+
expect(findNodesWithZeroAndOneParents([
25+
[1, 6], [1, 7], [1, 7], [2, 6], [2, 7], [3, 2], [3, 4],
26+
[4, 8], [5, 8], [6, 9], [6, 10], [7, 11], [8, 11], [8, 12]
27+
])).toEqual([
28+
[1, 3, 5],
29+
[2, 4, 9, 10, 12]
30+
]);
31+
})
32+
});

src/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
/**
2+
* This function find the nodes with zero and one parents
3+
* @param {number[][]} parentChildPairs
4+
* @returns {number[][]}
5+
*/
6+
const findNodesWithZeroAndOneParents = (parentChildPairs) => {
7+
8+
}
9+
10+
module.exports = findNodesWithZeroAndOneParents;

0 commit comments

Comments
 (0)