Skip to content

Commit 54f38ed

Browse files
committed
Add solution #1108
1 parent 0efa425 commit 54f38ed

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/**
2+
* 1108. Defanging an IP Address
3+
* https://leetcode.com/problems/defanging-an-ip-address/
4+
* Difficulty: Easy
5+
*
6+
* Given a valid (IPv4) IP address, return a defanged version of that IP address.
7+
*
8+
* A defanged IP address replaces every period "." with "[.]".
9+
*/
10+
11+
/**
12+
* @param {string} address
13+
* @return {string}
14+
*/
15+
var defangIPaddr = function(address) {
16+
return address.replace(/\./g, '[.]');
17+
};
18+
19+
// or...
20+
21+
/**
22+
* @param {string} address
23+
* @return {string}
24+
*/
25+
var defangIPaddr = function(address) {
26+
return address.split('.').join('[.]');
27+
};

0 commit comments

Comments
 (0)