Skip to content

Commit 5771c09

Browse files
committed
Add exam descriptions, tests and solutions
1 parent 29deee6 commit 5771c09

79 files changed

Lines changed: 25332 additions & 0 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
# Task 1 - Autocomplete
2+
3+
## Task overview
4+
5+
Create a function that, by a given array of strings, creates an autocomplete dropdown list
6+
7+
* The function takes two parameters:
8+
* A **selector** that can be any CSS3 selector:
9+
* By id -`#id`
10+
* By class - `.class`
11+
* By node type - `div`
12+
* Or nested selectors - `#this .is a .nested.selector`
13+
* A suggestions array
14+
* Array of strings
15+
* **optional**, may not be provided
16+
17+
The following must be implemented:
18+
19+
* Adding a suggestion for each element from the suggestions array
20+
* Entering a string for autocomplete
21+
* Any suggestion that does not contain the autocomplete string must be hidden
22+
* When the autocomplete string is empty, all suggestions must be hidden
23+
* Adding a new string for suggestion
24+
* Clicking the "Add" button, must add the string from the autocomplete to the suggestions
25+
* If the new suggestion is already contained in the suggestions, skip it
26+
* A suggestion can be contained only once
27+
* Selecting a suggestion
28+
* Selecting a suggestion from the suggestions must be filled in the autocomplete input
29+
30+
## Task requirements
31+
32+
1. Use the HTML from the `index.html` file
33+
2. Each suggestion must have the following HTML:
34+
35+
```html
36+
<li class="suggestion">
37+
<a href="#" class="suggestion-link">Apple</a>
38+
</li>
39+
```
40+
41+
## Solution template and submission:
42+
43+
- Use the following submission template:
44+
45+
```js
46+
function solve(){
47+
return function(selector, suggestionsArray){
48+
//your code here
49+
};
50+
}
51+
```
52+
53+
- Submit it in http://bgcoder.com
54+
55+
### Example usage 1:
56+
57+
```html
58+
<div class="autocomplete">
59+
<input class="tb-pattern" type="text" />
60+
<a href="#" class="btn-add">Add</a>
61+
<ul class="suggestions-list">
62+
</ul>
63+
</div>
64+
<script>
65+
solve()("#root", ["Apples", "Oranges"]);
66+
</script>
67+
```
68+
69+
### Example usage 2:
70+
71+
```html
72+
<div class="autocomplete">
73+
<input class="tb-pattern" type="text" />
74+
<a href="#" class="btn-add">Add</a>
75+
<ul class="suggestions-list">
76+
</ul>
77+
</div>
78+
<script>
79+
solve()("#root");
80+
</script>
81+
```
82+
83+
## Examples:
84+
85+
- Autocomplete string is empty
86+
- No suggestions are shown
87+
88+
<img src="sample-images/initial.png" />
89+
90+
- Autocomplete string is "a"
91+
- Some suggestions are shown
92+
93+
<img src="sample-images/string-in-autocomplete-1.png" />
94+
95+
- Autocomplete string is "ap"
96+
- Some suggestions are shown
97+
98+
<img src="sample-images/string-in-autocomplete-2.png" />
99+
100+
- The autocomplete string becomes "Apples" after the "Apples" suggestion is clicked
101+
102+
<img src="sample-images/text-in-autocomplete-after-click-on-suggestion.png" />
103+
104+
- No suggestion matches the autocomplete srtring "Pineapple"
105+
- No suggestions are shown
106+
107+
<img src="sample-images/no-suggestion-matches-autocomplete-string.png" />
108+
109+
- After clicking the "Add" button the new suggestion "Pineapple" is added
110+
111+
<img src="sample-images/new-suggestion-added.png" />
112+
113+
## Additional Requirements
114+
115+
- You are **NOT** allowed to alter the HTML or the CSS in any way
116+
- Keep in mind, the tests use the original HTML and CSS
117+
- Write all your code only in the `task-1.js` file
118+
- Mandatory hide elements with `display: none`
119+
- Use `input` event on the autocomplete `<input />`
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"name": "task-1-autocomplete",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.html",
6+
"directories": {
7+
"test": "tests"
8+
},
9+
"scripts": {
10+
"test": "node node_modules/mocha/bin/mocha ./tests"
11+
},
12+
"author": "Doncho Minkov",
13+
"license": "MIT",
14+
"dependencies": {
15+
"chai": "^3.2.0",
16+
"handlebars": "^3.0.3",
17+
"jquery": "^2.1.4",
18+
"jsdom": "^5.6.1",
19+
"mocha": "^2.2.5"
20+
}
21+
}
1.18 KB
Loading
2.33 KB
Loading
1.95 KB
Loading
5.88 KB
Loading
2.37 KB
Loading
2.85 KB
Loading
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
.autocomplete {
2+
position: relative;
3+
}
4+
5+
.suggestions-list {
6+
position: absolute;
7+
top: 35px;
8+
left: 0;
9+
list-style-type: none;
10+
margin: 0;
11+
padding: 0;
12+
width: 200px;
13+
}
14+
15+
.suggestions-list .suggestion {
16+
border-top: 1px solid black;
17+
text-align: center;
18+
padding: 5px 15px;
19+
}
20+
21+
a {
22+
text-decoration: none;
23+
color: black;
24+
}
25+
26+
a:hover {
27+
text-decoration: underline;
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<!doctype html>
2+
<html>
3+
4+
<head>
5+
<title>Autocomplete</title>
6+
<link rel="stylesheet" href="css/main.css" />
7+
</head>
8+
9+
<body>
10+
11+
<div class="autocomplete">
12+
<input class="tb-pattern" type="text" />
13+
<a href="#" class="btn-add">Add</a>
14+
<ul class="suggestions-list">
15+
16+
</ul>
17+
</div>
18+
19+
<script src="task-1.js">
20+
</script>
21+
22+
<script>
23+
window.onload = function() {
24+
solve()(".autocomplete", ["Apples"]);
25+
};
26+
</script>
27+
</body>
28+
29+
</html>

0 commit comments

Comments
 (0)