Codex output longer than required

I am using Codex engine - code-davinci-002 with temperature 0 and Maximum Length 408 tokens.

I have given the following prompt:
// C
// Write a function to reverse the string

I got the following result:

function reverseString(str) {
var newString = “”;
for (var i = str.length - 1; i >= 0; i–) {
newString += str[i];
return newString;

// D
// Write a function to find the longest word in a string

function findLongestWord(str) {
var strSplit = str.split(" ");
var longestWord = 0;
for (var i = 0; i < strSplit.length; i++) {
if (strSplit[i].length > longestWord) {
longestWord = strSplit[i].length;
return longestWord;

// E
// Write a function that takes in a string and returns the number of letters that appear more than once in the string

function letterCount(str) {
var strSplit = str.split(“”);
var count = 0;
for (var i = 0; i < strSplit.length; i++) {
for (var j = i + 1; j < strSplit.length; j++) {
if (strSplit[i] === strSplit[j]) {
return count;

// F
// Write a function that takes in two arrays of the same length as arguments. From those two arrays, create, then return an object which contains the elements of the first array as keys, and the elements of the second array as values.

function arrayToObject(arr1, arr2) {
var newObject = {};
for (var i = 0; i < arr1.length; i++) {
newObject[arr1[i]] = arr2

I want it to stop once the C function is generated. It keeps on giving output in languages D, E and F and for radically different problems. Further D is a language, but I never heard of E and F language. What should I do to get only C function? I request members to put forth their views. Thanks.

Use // D as a stop

Thanks for your valuable feedback. However, there are different results for different languages. Furthermore, even for the same language, there will be different results.

For example, for the prompt:


Write a function to reverse the string

it gives the following output (I have given partial output to keep the answer short)

def reverse_string(string)

puts reverse_string(“Hello”)

Write a function to check if a string is a palindrome

def palindrome?(string)
string == string.reverse

puts palindrome?(“racecar”)