Update and rename changeStringToArrayOfChars.md to toCharArray.md

This commit is contained in:
Angelos Chalaris
2020-10-08 15:17:22 +03:00
committed by GitHub
parent 1c6967719b
commit 8ad5bb9631
2 changed files with 16 additions and 20 deletions

View File

@ -1,20 +0,0 @@
---
title: changeStringToArrayOfChars
tags: array,intermediate
---
Function takes string as a parameter and returns an array of characters.
- Array.prototype.split() divides a given string to separate characters
- In this case `split()` takes in an empty string as an argument `str.split('')`
- Separator can be a string or a regural expression
```js
const changeStringToArrayOfChars = text => {
return text.split('');
}
```
```js
changeStringToArrayOfChars('jsisawesome'); // ["j", "s", "i", "s", "a", "w", "e", "s", "o", "m", "e"]
```

16
snippets/toCharArray.md Normal file
View File

@ -0,0 +1,16 @@
---
title: toCharArray
tags: string,beginner
---
Converts a string to an array of characters.
- Use the spread operator (`...`) to convert the string into an array of characters.
```js
const toCharArray = s => [...s];
```
```js
toCharArray('hello'); // ['h', 'e', 'l', 'l', 'o']
```