Solved: 28 - Algorithm Lambdas

This commit is contained in:
2026-08-16 12:15:10 +03:00
parent 5f4bbc0918
commit 7a8e430982
@@ -1,20 +1,29 @@
#include "algorithm_lambdas.hpp"
#include <algorithm>
namespace stl_algorithms {
auto filter_length(const std::vector<std::string>& words, std::size_t min_len)
-> std::vector<std::string> {
(void)words; (void)min_len;
return {};
const auto is_valid = [min_len](const auto& word) { return word.size() >= min_len; };
auto r = std::vector<std::string>();
std::ranges::copy_if(words,std::back_inserter(r), is_valid);
return r;
}
auto map_to_lengths(const std::vector<std::string>& words) -> std::vector<int> {
(void)words;
return {};
auto r = std::vector<int>();
for (const auto& word : words) {
r.push_back(static_cast<int>(word.size()));
}
return r;
}
auto first_match(const std::vector<int>& data, int threshold) -> int {
(void)data; (void)threshold;
auto first_match(const std::vector<int>& data, const int threshold) -> int {
for (const auto& value : data) {
if (value >= threshold) return value;
}
return -1;
}