Partitioning input strings by even and odd indexes I have been trying to learn javascript for a year now, and have just embarked on HackerRank's 30 days of code. After a couple of days I finally solved this problem. Here is the task (if you click the link, press x to the signup page):


  Task 
  
  Given a string S of length N that is indexed from 0  to N-1, print its even-indexed and odd-indexed characters as  space-separated strings on a single line (see the Sample below for more detail).
  
  Sample Input
  
  2
     Hacker
     Rank
  
  Sample Output
  
  Hce akr
     Rn ak


Here is my solution. Any performance optimizations I could make here?: 

function processData(input) {
    //Enter your code here

    //split the string into an array
    let words = input.split("\n").slice(1),
    odd = "",
    even = "",
    newStr = "";
    //turn each string inside the array into its own array
    let wordsArr = words.map((val) =&gt; {
        return val.split("");
    })
    //outer loop for the outer array
    for (let i = 0, len = wordsArr.length; i &lt; len; i++){
          //inner loop for the inner arrays
        for (let j = 0, len2 = wordsArr[i].length; j &lt; len2; j++){
         //if the index is even or odd, add to the respective strings
             if (j % 2 === 0){
                even += wordsArr[i][j]
            } else if (j % 2 !== 0) {
                odd += wordsArr[i][j];
            }       

            //if the end of the array is detected, print the string
            //and set odd/even strings to be blank for the next iteration
            if (j == len2 - 1){
                newStr = `${even} ${odd}`;
                even = "";
                odd = "";
                console.log(newStr);
            }
    }             
} 

}
One possible solution that achieves the described result is:

`${s.replace(/./g, (s, pos) =&gt; [s, ''][pos &amp; 1])} ${s.replace(/./g, (s, pos) =&gt; ['', s][pos &amp; 1])}`


...But in order to answer to your question:

// 0
let wordsArr = words.map((val) =&gt; {
    return val.split("");
})

// can be rewritten as
let wordsArr = words.map(val =&gt; val.split(''))

// 1
for (let i = 0, len = wordsArr.length; i &lt; len; i++){

// personally I use
i += 1
// following to Douglas Crockford
// this is what actually happens under the hood

// 2
if (j % 2 === 0){
   even += wordsArr[i][j]
} else if (j % 2 !== 0) {
   odd += wordsArr[i][j];
}

// can be symplified to
[even, odd][j &amp; 1] += wordsArr[i][j];


Happy coding!