diff --git a/exercises/practice/flatten-array/.docs/instructions.md b/exercises/practice/flatten-array/.docs/instructions.md index 51bea67..b5b8271 100644 --- a/exercises/practice/flatten-array/.docs/instructions.md +++ b/exercises/practice/flatten-array/.docs/instructions.md @@ -1,11 +1,16 @@ # Instructions -Take a nested list and return a single flattened list with all values except nil/null. +Take a nested array of any depth and return a fully flattened array. -The challenge is to write a function that accepts an arbitrarily-deep nested list-like structure and returns a flattened structure without any nil/null values. +Note that some language tracks may include null-like values in the input array, and the way these values are represented varies by track. +Such values should be excluded from the flattened array. -For example: +Additionally, the input may be of a different data type and contain different types, depending on the track. -input: [1,[2,3,null,4],[null],5] +Check the test suite for details. -output: [1,2,3,4,5] +## Example + +input: `[1, [2, 6, null], [[null, [4]], 5]]` + +output: `[1, 2, 6, 4, 5]` diff --git a/exercises/practice/flatten-array/.docs/introduction.md b/exercises/practice/flatten-array/.docs/introduction.md new file mode 100644 index 0000000..a314857 --- /dev/null +++ b/exercises/practice/flatten-array/.docs/introduction.md @@ -0,0 +1,7 @@ +# Introduction + +A shipment of emergency supplies has arrived, but there's a problem. +To protect from damage, the items — flashlights, first-aid kits, blankets — are packed inside boxes, and some of those boxes are nested several layers deep inside other boxes! + +To be prepared for an emergency, everything must be easily accessible in one box. +Can you unpack all the supplies and place them into a single box, so they're ready when needed most? diff --git a/exercises/practice/flatten-array/.meta/tests.toml b/exercises/practice/flatten-array/.meta/tests.toml index 6300219..44acf17 100644 --- a/exercises/practice/flatten-array/.meta/tests.toml +++ b/exercises/practice/flatten-array/.meta/tests.toml @@ -32,12 +32,32 @@ description = "null values are omitted from the final result" [c6cf26de-8ccd-4410-84bd-b9efd88fd2bc] description = "consecutive null values at the front of the list are omitted from the final result" +include = false + +[bc72da10-5f55-4ada-baf3-50e4da02ec8e] +description = "consecutive null values at the front of the array are omitted from the final result" +reimplements = "c6cf26de-8ccd-4410-84bd-b9efd88fd2bc" [382c5242-587e-4577-b8ce-a5fb51e385a1] description = "consecutive null values in the middle of the list are omitted from the final result" +include = false + +[6991836d-0d9b-4703-80a0-3f1f23eb5981] +description = "consecutive null values in the middle of the array are omitted from the final result" +reimplements = "382c5242-587e-4577-b8ce-a5fb51e385a1" [ef1d4790-1b1e-4939-a179-51ace0829dbd] description = "6 level nest list with null values" +include = false + +[dc90a09c-5376-449c-a7b3-c2d20d540069] +description = "6 level nested array with null values" +reimplements = "ef1d4790-1b1e-4939-a179-51ace0829dbd" [85721643-705a-4150-93ab-7ae398e2942d] description = "all values in nested list are null" +include = false + +[51f5d9af-8f7f-4fb5-a156-69e8282cb275] +description = "all values in nested array are null" +reimplements = "85721643-705a-4150-93ab-7ae398e2942d" diff --git a/exercises/practice/flatten-array/flatten_array_test.gd b/exercises/practice/flatten-array/flatten_array_test.gd index 7949fed..402dedd 100644 --- a/exercises/practice/flatten-array/flatten_array_test.gd +++ b/exercises/practice/flatten-array/flatten_array_test.gd @@ -40,25 +40,25 @@ func test_null_values_are_omitted_from_the_final_result(solution_script): return [solution_script.flatten(inputs), expected] -func test_consecutive_null_values_at_the_front_of_the_list_are_omitted_from_the_final_result(solution_script): +func test_consecutive_null_values_at_the_front_of_the_array_are_omitted_from_the_final_result(solution_script): var inputs = [null, null, 3] var expected = [3] return [solution_script.flatten(inputs), expected] -func test_consecutive_null_values_in_the_middle_of_the_list_are_omitted_from_the_final_result(solution_script): +func test_consecutive_null_values_in_the_middle_of_the_array_are_omitted_from_the_final_result(solution_script): var inputs = [1, null, null, 4] var expected = [1, 4] return [solution_script.flatten(inputs), expected] -func test_6_level_nest_list_with_null_values(solution_script): +func test_6_level_nest_array_with_null_values(solution_script): var inputs = [0, 2, [[2, 3], 8, [[100]], null, [[null]]], -2] var expected = [0, 2, 2, 3, 8, 100, -2] return [solution_script.flatten(inputs), expected] -func test_all_values_in_nested_list_are_null(solution_script): +func test_all_values_in_nested_array_are_null(solution_script): var inputs = [null, [[[null]]], null, null, [[null, null], null], null] var expected = [] return [solution_script.flatten(inputs), expected]