// https://www.interviewcake.com/question/javascript/reverse-string-in-place?course=fc1§ion=array-and-string-manipulation
// Reverse the input array of characters in place
function reverse(arrayOfChars) {
	let i = 0,
		j = arrayOfChars.length - 1
	while (i < j) {
		swap(arrayOfChars, i, j)
		i++
		j--
	}
}

//Helper function
function swap(array, i, j) {
	let temp = array[i]
	array[i] = array[j]
	array[j] = temp
}

/*
Time Complexity - O(n)
Space complexity - O(1)
*/

/* ---------------------------------------------------------------------------- */

const testCases = [
	['abcd', 'dcba'],
	['', ''],
	['a', 'a'],
	['AndD', 'DdnA'],
]

for (const test of testCases) {
	const arr = test[0].split('')
	reverse(arr)
	console.log(arr.join('') === test[1])
}