Generation

code to explanationSat, 03 Dec 2022

def joinWords(stringArr,delimiter): res = "" for i in range(len(stringArr)): res += stringArr[i] + delimiter print(res.substring(0, res.length - 1))

The code above does the following: 1. Define a function that takes 2 arguments, an Array of Strings and a delimiter 2. Initialize a variable named res to an empty string 3. Loop over the array using a for loop 4. Concatenate each element with the delimiter and add it to res 5. Print the result without the last delimiter

Questions about programming?Chat with your personal AI assistant