Skip to content

Commit 34ee41a

Browse files
authored
Merge branch 'dostonnabotov:main' into frameworks-frontend
2 parents 4aa4a46 + 4a7a8b2 commit 34ee41a

File tree

5 files changed

+157
-0
lines changed

5 files changed

+157
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
---
2+
Title: Filter
3+
Description: Filters a vector using a predicate function.
4+
Author: majvax
5+
Tags: array,filter,c++23
6+
---
7+
8+
```cpp
9+
#include <ranges>
10+
#include <vector>
11+
12+
template <typename T, typename P>
13+
auto filter(const std::vector<T>& vec, P&& predicate) {
14+
return vec
15+
| std::views::filter(std::forward<P>(predicate))
16+
| std::ranges::to<std::vector<T>>();
17+
}
18+
19+
20+
21+
// Usage:
22+
std::vector<int> vec = {1, 2, 3, 4, 5};
23+
std::vector<int> filtered = filter(vec, [](int i){ return i % 2 == 0; });
24+
// filtered contains 2 and 4
25+
```
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
---
2+
title: Remove duplicates
3+
description: Removes duplicates from an vector of ints
4+
author: AnkushRoy-code
5+
tags: vector,remove,duplicate
6+
contributor: majvax
7+
---
8+
9+
```cpp
10+
#include <algorithm>
11+
#include <vector>
12+
13+
bool removeDuplicates(std::vector<int> &input) noexcept {
14+
if (input.empty()) return false;
15+
const auto size = input.size();
16+
std::sort(input.begin(), input.end());
17+
18+
auto last = std::unique(input.begin(), input.end()); // remove duplicates
19+
input.erase(last, input.end()); // resize vector and delete the undefined elements
20+
21+
return size != input.size();
22+
}
23+
24+
25+
26+
// Usage:
27+
std::vector<int> vec = {4, 2, 2, 8, 5, 6, 9, 9, 9, 8, 8, 4};
28+
removeDuplicates(vec); // returns {2, 4, 5, 6, 8, 9}
29+
```
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Remove n Occurences
3+
description: Removes duplicates from an vector of ints
4+
author: AnkushRoy-code
5+
tags: vector,remove
6+
contributor: majvax
7+
---
8+
9+
```cpp
10+
#include <algorithm>
11+
#include <unordered_map>
12+
#include <vector>
13+
14+
bool removeOccurrences(std::vector<int>& vec, const unsigned int n) noexcept {
15+
if (vec.empty() || n == 0) return false;
16+
17+
const auto size = vec.size();
18+
std::unordered_map<int, int> frequency; // count frequencies
19+
for (int num : vec) {
20+
frequency[num]++;
21+
}
22+
23+
vec.erase( // remove elements with n number of occurrences
24+
std::remove_if(vec.begin(), vec.end(), [&frequency, n](const int x) {
25+
return frequency[x] == n;
26+
}),
27+
vec.end()
28+
);
29+
return size != vec.size();
30+
}
31+
32+
33+
34+
// Usage:
35+
std::vector<int> vec = {4, 2, 4, 8, 5, 6, 8, 8, 4, 3 };
36+
37+
int n = 3; // Remove elements that occur exactly 3 times
38+
removeOccurrences(vec, n); // returns {2, 5, 6, 3}
39+
```
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
---
2+
Title: Transform
3+
Description: Transforms a vector using a function.
4+
Author: majvax
5+
Tags: array,transform,c++23
6+
---
7+
8+
```cpp
9+
#include <ranges>
10+
#include <vector>
11+
12+
template <typename T, typename F>
13+
auto transform(const std::vector<T>& vec, F&& transformer) {
14+
using U = std::invoke_result_t<F, T>;
15+
return vec
16+
| std::views::transform(std::forward<F>(transformer))
17+
| std::ranges::to<std::vector<U>>();
18+
}
19+
20+
21+
22+
// Usage:
23+
std::vector<int> vec = {1, 2, 3, 4, 5};
24+
std::vector<int> transformed = transform(vec, [](int i){ return i * 2; });
25+
// transformed contains 2, 4, 6, 8, 10
26+
```
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
title: RGB Border Color Animation
3+
description: changes border of an Element to rgb onhover (Can be changed)'
4+
author: Brianali-codes
5+
tags: animation,effects,borders
6+
---
7+
8+
```css
9+
.yourElement {
10+
/* Your Elements styles go here*/
11+
border-style: solid;
12+
border-radius: 10px;
13+
color: rgb(0, 0, 0);
14+
15+
}
16+
.yourElement:hover {
17+
18+
animation: change-color;
19+
animation-duration: 0.5s; /* you can alter the duration of the animation here. */
20+
animation-iteration-count: infinite; /* Choose to play animation infinitely or once on hover. */
21+
}
22+
23+
@keyframes change-color {
24+
0% {
25+
border-color: red;
26+
}
27+
28+
50% {
29+
border-color: green;
30+
}
31+
32+
100% {
33+
border-color: blue;
34+
}
35+
}
36+
37+
38+
```

0 commit comments

Comments
 (0)