Day 03: 30 Days of Codewars.js
Tags: challenge, 100daysofcode, javascript, todayilearned
Published: 2020-04-24 20:30:12

> ## Table Of Contents
   * [Testing 1-2-3](#kata-1)
     - 📃 [Description](#kata-1-desc)
     - 🤔 [Thinking](#kata-1-think)
     - 👨‍💻 [Code](#kata-1-code)
   * [Stop gninnipS My sdroW!](#kata-2)
     - 📃 [Description](#kata-2-desc)
     - 🤔 [Thinking](#kata-2-think)
     - 👨‍💻 [Code](#kata-2-code)
   * [Credit Card Mask](#kata-3)
     - 📃 [Description](#kata-3-desc)
     - 🤔 [Thinking](#kata-3-think)
     - 🤷‍♂️ [What?](#kata-3-what)
     - 👨‍💻 [Code](#kata-3-code)

---

<a name="kata-1"></a>
# Testing 1-2-3 : ✍ by [acr](https://www.codewars.com/users/acr)

<a name="kata-1-desc"></a>
### 📃 Description
> Write a function which takes a list of strings and returns each line prepended by the correct number.

#### Examples: 
```javascript
number([]) // => []
number(["a", "b", "c"]) // => ["1: a", "2: b", "3: c"]
```

<a name="kata-1-think"></a>
### 🤔 Thinking
`map` over the array and return an array using template literal every element with its `index`

<a name="kata-1-code"></a>
### 👨‍💻 Code
```javascript
const number = arr => arr.map((elm, i) => `${i+1}: ${elm}`)
```

---

<a name="kata-2"></a>
# Stop gninnipS My sdroW! : ✍ by [xDranik](https://www.codewars.com/users/xDranik)

<a name="kata-2-desc"></a>
### 📃 Description
> Write a function that takes in a string of one or more words, and returns the same string, but with `all five or more letter words reversed` (Just like the name of this Kata). Strings passed in will consist of only letters and spaces. Spaces will be included only when more than one word is present.

#### Examples: 
```javascript
spinWords( "Hey fellow warriors" ) // => "Hey wollef sroirraw"
spinWords( "This is a test") // =>"This is a test"
spinWords( "This is another test" ) // =>"This is rehtona test"
```
<a name="kata-2-think"></a>
### 🤔 Thinking
Turn the string into an `array` of words (strings)
Then Check if the word length >= 5
If `true` I will `reverse` the word(s)
Then `join` it all

<a name="kata-2-code"></a>
### 👨‍💻 Code
```javascript
const spinWords = str => {
  const arr = str.split(" ");
  const spinedarr = arr.map(word => {
   return word.length >= 5 ? word.split("").reverse().join("") : word;
  })
  
  return spinedarr.join(" ");
}
```

---

<a name="kata-3"></a>
# Credit Card Mask : ✍ by [samranjbari](https://www.codewars.com/users/samranjbari)

<a name="kata-3-desc"></a>
### 📃 Description
> Write a function maskify, which changes all but the last four characters into '#'.

#### Examples:
```javascript
maskify("4556364607935616") // => "############5616"
maskify(     "64607935616") // =>      "#######5616"
maskify(               "1") // =>               "1"
```

<a name="kata-3-think"></a>
### 🤔 Thinking
I'm will make an `array` and then `slice` it so I get the last 4 digits
Then use the `padStart` method to create a string with the same length with that starts with `#`s 

<a name="kata-3-what"></a>
### 🤷‍♂️ What?
> #### MDN: 
The `padStart()` method pads the current string with another string (multiple times, if needed) until the resulting string reaches the given length. The padding is applied from the start of the current string.

<a name="kata-3-code"></a>
### 👨‍💻 Code
```javascript
const maskify = cc => {
  const last4 = cc.split("").slice(-4);
  
  const masked = cc.length >= 4 ? last4.join("").padStart(cc.length, "#") : cc;
  
  return masked
}
```

---

##### <center>If you know a better way to solve any of the previous katas let me know in the comment</center>

---

*<center>Thanks for reading, I really appreciate it.</center>*