Solved: 28 - Algorithm Lambdas
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user