Respuesta :
Answer:
The solution code is written in Python 3.
- def convertCSV(number_list):
- str_list = []
- for num in number_list:
- str_list.append(str(num))
- return ",".join(str_list)
- result = convertCSV([22,33,44])
- print(result)
Explanation:
Firstly, create a function, convertCSV(), that take one input which is a list of number, number_list. (Line 1)
Next, declare a new string list, str_list. (Line 2)
Use a for-loop to traverse the individual number in the number_list (Line 4) and add each of the number into the str_list. Please note, the individual number is converted to string type using Python str() method. (Line 5)
By now, the str_list should have a list of string type number. We can use join() method to join all the string element in the str_list into a single string and return it as an output. (Line 7) The "," acts as a separator between the element in the str_list.
We can test the function by passing a random list of number, (e.g. [22,33,44]) and the output shall be '22,33,44'. (Line 9 - 10)
In JavaScript, there are two functions that return string representations of an array: join() and toString().
String Representations of Arrays
function convertToString (number_list){
number_list.join(",")
return number_list
}
In the function above, we do not need to loop through the list to convert the integer array to string array, the join() function is a javaScript method that converts a list of string automatically, having specified the delimiter as a comma, the function will return a comma separated string of the input
Learn more about arrays here:
https://brainly.com/question/26104158