Edabit Fby397fv37HCNHZy8

https://edabit.com/challenge/Fby397fv37HCNHZy8

by Gerald Gillespie

JavaScript

function charAtPos(r, s, ct = 0, exportArray) {
	/* your code in here */
	let isArray = Array.isArray(r);
  
  if( !isArray ){
  	r = r.join('')	
  }
  
  if( ct === 0){
  	exportArray = isArray
    ct = r.length
    if( s === 'even'){
    	r.shift()
      ct--
      s ='odd'
    }
  }
 	r.push ( r.shift() )
  ct--
  if( ct >= 1 ){
  	r.shift()
    ct--
  }
  //console.log(ct)
	if( ct > 0 ){
	  return charAtPos(r, s, ct, exportArray)
	} else {
  	//r is always an array right now
  	return exportArray ? r : r.split('')
  }
}


console.log(charAtPos(["A", "R", "B", "I", "T", "R", "A", "R", "I", "L", "Y"], "odd"))
console.log(charAtPos(["A", "R", "B", "I", "T", "R", "A", "R", "I", "L", "Y"], "even"))