# CC-08: String Mutation and Array Iteration

with Carmen Salas • 2024/10/16

## Code Challenge

1. Declare a function called `stripUpperCase` that takes in a string argument consistenting of only alphabet characters and returns a new string with all uppercase letters removed. Note: You should not alter the input str, this function should return a new string.

```js
// this function is pure!
const stripUpperCase = (str) => {
  let res = str.split('');
  return res.filter((char) => {
    if (char == char.toLowerCase()) { return char; }
  }).join('');
}

// console.log('Hello');
// console.log(stripUpperCase('Hello')); // 'ello'
// console.log('SevenEleven');
// console.log(stripUpperCase('SevenEleven')); // 'evenleven'
// console.log('code challenge is fun');
// console.log(stripUpperCase("code challenge is fun")); // 'code challenge is fun'
```

2. Declare a function named `findLongestWord`, that takes an array of strings as an argument, and returns the longest string in the array. If there is more than one longest string, the function should return the **first** longest string that appears in the array. You must solve this without using any array methods.

```js
const findLongestWord = (arr) => {
  // without using array methods:
  // let res = '';
  // for (let word of arr) {
  //   if (word.length > res.length) { res = word; };
  // }
  // return res;
   
  // using reduce!
  return arr.reduce((res, curr) =>
   (curr.length > res.length) ? curr : res);
}

// console.log(findLongestWord(["The","quick","brown", "fox", "jumped", "over", "the", "lazy", "dog"]));
// console.log(findLongestWord(["jazzy", "jumpy", "quaky"])) //returns "jazzy"
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://raffycastlee.gitbook.io/marcyannotes/codechallenge-curriculum/unit-2/20241016.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
