@KK998/

flipEveryNChars

JavaScript

Another great problem.

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 flipEveryNChars(input, number)
{
  //create array of strings for the number < input
  let arr = [];

	//create a string from input for the length of the number.
  for(let i = 0; i < input.length; i += number){
  	let temp = "";

  	// extract number amount of chars from str to temp 
  	temp = input.substr(i, number);

  	// reverse the temp (the extracted section from str)
  	arr.push(temp.split("").reverse().join(""));
  }

  // Join the strings together.
  return arr.join("");
}

//Tests
let input = 'a short example'; 
flipEveryNChars(input, 5);
Native Browser JavaScript