Skip to content

Commit 4ac240f

Browse files
committed
Added String.RemoveAt
1 parent 70d7341 commit 4ac240f

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

src/utils/string/RemoveAt.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/**
2+
* @author Richard Davey <rich@photonstorm.com>
3+
* @copyright 2020 Photon Storm Ltd.
4+
* @license {@link https://opensource.org/licenses/MIT|MIT License}
5+
*/
6+
7+
/**
8+
* Takes a string and removes the character at the given index.
9+
*
10+
* @function Phaser.Utils.String.RemoveAt
11+
* @since 3.50.0
12+
*
13+
* @param {string} string - The string to be worked on.
14+
* @param {number} index - The index of the character to be removed.
15+
*
16+
* @return {string} The modified string.
17+
*/
18+
var RemoveAt = function (string, index)
19+
{
20+
if (index === 0)
21+
{
22+
return string.slice(1);
23+
}
24+
else
25+
{
26+
return string.slice(0, index - 1) + string.slice(index);
27+
}
28+
};
29+
30+
module.exports = RemoveAt;

src/utils/string/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ module.exports = {
1212

1313
Format: require('./Format'),
1414
Pad: require('./Pad'),
15+
RemoveAt: require('./RemoveAt'),
1516
Reverse: require('./Reverse'),
1617
UppercaseFirst: require('./UppercaseFirst'),
1718
UUID: require('./UUID')

0 commit comments

Comments
 (0)