I need a .map()
Published: 2021-11-09 20:18:09

Welcome to my journey to being a software engineer!

 I began my journey at Flatiron School. Flatiron is a coding bootcamp, that teaches you to become a full stack developer in fifteen weeks. Fifteen weeks is an incredibly short amount of time to become a full stack developer, so the program moves fast. By the end of the first day I was already I was starting to question what I got myself into. Tuesday began and we started to get into more and more complex function and JavaScript commands, and I barely grasped what I learned Monday. This was starting to get out of hand, but I was optimistic. I knew what I was doing and I knew I could succeed. 

 And then Wednesday. Array Iteration, and the  .map() lab. 






The lab was simple enough I had to take an array and capitalize every letter in the array. 

[
          "What Does The This Keyword Mean?",
          "What Is The Constructor OO Pattern?",
          "Implementing Blockchain Web API",
          "The Test Driven Development Workflow",
          "What Is NaN And How Can We Check For It",
          "What Is The Difference Between StopPropagation And PreventDefault?",
          "Immutable State And Pure Functions",
          "What Is The Difference Between == And ===?",
          "What Is The Difference Between Event Capturing And Bubbling?",
          "What Is JSONP?"
      ]


This is easy.
let result = tutorials.map(cap)

function cap(string){
let firstletter = string.slice(0,1).toUpperCase();
let restWord = string.slice(1);
let y = firstletter + restWord
  return y
}

console.log(result)


Bam!
I use the Cap function here to capitalize the first letter of every .... wait a sec, this is only going to capitalize the first letter of every element. 

You see in the first line of the Cap() function the  .slice() function will take the first letter of every string in the array and when combined with the .toUpperCase function will  capitalize it.  Then the second line then will take the rest of the string, and the third line will combine then. 
The .map function allows up to apply this action to every element tin the array.



Huh, looks like the next step should be to find a way to separate the arrays into even more arrays with one array per word. 


function splitToString(array){
let string = array.join()
console.log(string)
let array2 = string.split(" ")
console.log(array2)

}






So after some Google-fu I found the .Join() and .split() functions. 
.join will make an array into a string and .split will separate the a string into an array, where it will split it based on the character you decide. In this case. I choose a space. 

The result?

[    "What",    "Does",    "The",    "This",    "Keyword",    "Mean?,What",    "Is",    "The",    "Constructor",    "OO",    "Pattern?,implementing",    "Blockchain",    "Web",    "API,The",    "Test",    "Driven",    "Development",    "Workflow,What",    "Is",    "NaN",    "And",    "How",    "Can",    "We",    "Check",    "For",    "It,What",    "Is",    "The",    "Difference",    "Between",    "StopPropagation",    "And",    "PreventDefault?,Immutable",    "State",    "And",    "Pure",    "Functions,what",    "Is",    "The",    "Difference",    "Between",    "==",    "And",    "===?,what",    "Is",    "The",    "Difference",  [
    "What",
    "Does",
    "The",
    "This",
    "Keyword",
    "Mean?,What",
    "Is",
    "The",
    "Constructor",
    "OO",
    "Pattern?,implementing",
    "Blockchain",
    "Web",
    "API,The",
    "Test",
    "Driven",
    "Development",
    "Workflow,What",
    "Is",
    "NaN",
    "And",
    "How",
    "Can",
    "We",
    "Check",
    "For",
    "It,What",
    "Is",
    "The",
    "Difference",
    "Between",
    "StopPropagation",
    "And",
    "PreventDefault?,Immutable",
    "State",
    "And",
    "Pure",
    "Functions,what",
    "Is",
    "The",
    "Difference",
    "Between",
    "==",
    "And",
    "===?,what",
    "Is",
    "The",
    "Difference",
    "Between",
    "Event",
    "Capturing",
    "And",
    "Bubbling?,what",
    "Is",
    "JSONP?"
]
  "Between",    "Event",    "Capturing",    "And",    "Bubbling?,what",    "Is",    "JSONP?"]
ect....

Uhhh that kind of worked. the letters at the end of an element and the begging of another didn't split but I think I can deal with that in another way. now I just have to join them together and.....







uhhh that's a lot of commas. Maybe if I split the no... 

After this I obsessed with this lab I spent days trying to solve it while slowly falling behind. And as out coding challenge was approaching, and I was falling behind.

We had a Pre-assessment before the coding challenge. In that Pre-assessment we had three deliverables.  I was able to achieve zero. This is when the imposter syndrome came into full effect.  I was convinced I had no chance of succeeding, I was convinced that this was the end of my journey. 


Then I hit the books and most importantly. I asked for help. After working with several of my classmates I was able to pass the coding challenge, and I was also able to figure out how to solve the .map lab. 

let result = tutorials.map(cap)

function cap(string){
let firstletter = string.slice(0,1).toUpperCase();
let restWord = string.slice(1);
let y = firstletter + restWord
  return y
}

function splitToString(array){
let string = array.join("**")
console.log(string)
let array2 = string.split(" ")
console.log(array2)
let results = array2.map(cap)
results =  results.join(" ")
results = results.split ("**")
results = results.map(cap)
return results
}


It was honestly simple. The split command lets you not use commas to separate the arrays. All I had to do was add a character.