gpt-4-1106-preview· OpenAI
Arena Human Preference 55K
Write a one line JS function that reverses an array without using any built in methods
- User
Write a one line JS function that reverses an array without using any built in methods
- Assistant
Certainly! Here's a one-liner JavaScript function that reverses an array without using any built-in methods:
javascriptconst reverseArray = arr => { for(let i=0, j=arr.length-1; i<j; i++, j--) { let temp = arr[i]; arr[i] = arr[j]; arr[j] = temp; } return arr; };This function uses a for loop to swap elements in the array starting from the beginning and the end, moving towards the center, effectively reversing the array in place.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.