JSFiddle - React, Tailwind, and code Playground

by Shridhar Baddur

JavaScript

function swapWords() {
	var string = "AAA BBB is XYZ ABC";
	//expected output "BBB AAA is ABC XYZ"  
  var array = string.split(" ");
  
  string = array[1] + " " + array[0] + " is " + array[array.length-1] + " " + array[array.length-2];
  
  console.log(string);
}
swapWords();