From 56b778db4f8eef98fb8681be50e5c1a0bd8edcd4 Mon Sep 17 00:00:00 2001
From: Abivarman <abivarman.kandiah@etu.hesge.ch>
Date: Thu, 24 Feb 2022 11:31:21 +0100
Subject: [PATCH] Modified vector map

---
 header/vectors.h   |  2 +-
 src/test_vectors.c | 11 +++++++----
 src/vectors.c      |  9 ++++++---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/header/vectors.h b/header/vectors.h
index 44ddb85..8c3dfca 100644
--- a/header/vectors.h
+++ b/header/vectors.h
@@ -30,6 +30,6 @@ void vector_insert(vector vec, type element, int index);
 void vector_empty(vector vec);
 void vector_free(vector vec);
 void vector_print(vector vec, void (*print)(type));
-void vector_map(vector vec, type (*f)(type));
+vector vector_map(vector vec, type (*f)(type));
 
 #endif
\ No newline at end of file
diff --git a/src/test_vectors.c b/src/test_vectors.c
index bc8f372..01db5a0 100644
--- a/src/test_vectors.c
+++ b/src/test_vectors.c
@@ -59,14 +59,17 @@ int main()
 	}
 	vector_print(test, &print_type);
 	printf("\n");
-	
+
 	//Test Vector map
-	vector_map(test, &times_two);
-	vector_print(test, &print_type);
+	vector test_2 = vector_map(test, &times_two);
+	vector_print(test_2, &print_type);
+
+	//Test Vector filter
 
 	//Test Vector Free
 	vector_free(test);
-
+	vector_free(test_2);
+	
 	return 0;
 }
 
diff --git a/src/vectors.c b/src/vectors.c
index d5dad3f..92590bb 100644
--- a/src/vectors.c
+++ b/src/vectors.c
@@ -137,10 +137,13 @@ void vector_print(vector vec, void (*print)(type))
 	}
 }
 
-void vector_map(vector vec, type (*f)(type))
+vector vector_map(vector vec, type (*f)(type))
 {
+	vector new_vec = vector_create();
 	for (int i = 0; i < vec->length; i++)
 	{
-		vec->content[i] = f(vec->content[i]);
+		vector_push(new_vec, f(vec->content[i]));
 	}
-}
\ No newline at end of file
+	return new_vec;
+}
+
-- 
GitLab