getFirstLetters

by SeasonEnds

JavaScript

function getFirstLetters(arrA, arrB) {
	// arrA and arrB are arrays of strings
  // arrA and arrB are the same size
  // return a new array result that is the same size
  
  // result arrays elements should be strings containing the first letter of strings from both "arrA" and "arrB" at each position
  
  // determine the length of the array
  let length = arrA.length;
  
  // Use map to get the first letter of array A and create a new array called firstArray
  const firstArray = arrA.map((letter) => letter[0])
  
  // Use map to get the first letter of Aray B and create a new array called secondArray
	const secondArray = arrB.map((letter) => letter[0])
  
  // Console log to see what the other arrays are
  console.log(firstArray);
  console.log(secondArray)
  
  // Create a new empty array
  let newArray = []
  
  // Do a for loop that uses the length of the above arrays to not loop too far
  for (var i = 0; i < length; i++) {
  // Use push to take the first letters from firstArray and secondArray and merge them into a new array
  	newArray.push(firstArray[i] + secondArray[i])
  }
  console.log(newArray)
  return newArray
}

// This is the example information they give you
arrA = ['ab', 'hello', 'javascript']
arrB = ['xyz', 'bye', 'python']
getFirstLetters(arrA, arrB);