@KK998/

flipPairsOfString

JavaScript

An interesting lesson I encountered while finishing Repl.it JavaScript lessons

fork
loading
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function flipPairs(input)
{
	let arr = [];
	let arr2 = [];

	//create the pairs
	for(let i = 0; i < input.length; i += 2){
		let temp = [];
		temp.push(input[i])
		temp.push(input[i+1])
		arr.push(temp)
	}
	//flip the pairs
	arr.forEach(array => {
		let first = array[0];
		let second = array[1];
		
		arr2.push(second, first)
	})
	//Create output \STRING\
  return arr2.join("")
}
flipPairs('check out how interesting this problem is, it\'s insanely interesting!')
Native Browser JavaScript