IP地址无效化

This commit is contained in:
yi-ge 2020-05-19 06:03:33 +08:00
parent 34a76e22b9
commit 32fd589c3f
4 changed files with 20 additions and 0 deletions

View File

@ -2,10 +2,13 @@
"cSpell.words": [
"Gitpod",
"LVIII",
"Paddr",
"Prinme",
"abcdefg",
"cdefgab",
"chuan",
"defang",
"defanging",
"dvdf",
"lcci",
"lcof",

View File

@ -91,6 +91,10 @@ LeetCode 与 LintCode 解题记录。此为个人练习仓库,代码中对重
- LeetCode 680. 验证回文字符串 Ⅱ <https://leetcode-cn.com/problems/valid-palindrome-ii/>
- LintCode 891. 有效回文 II <https://www.lintcode.com/problem/valid-palindrome-ii/description>
- [IP地址无效化](src/string/defanging-an-ip-address.js)
- LeetCode 1108. IP 地址无效化 <https://leetcode-cn.com/problems/defanging-an-ip-address/>
## 数组/队列/集合/映射
- [电话号码的字母组合](src/array/letter-combinations-of-a-phone-number.js)

View File

@ -0,0 +1,7 @@
/**
* @param {string} address
* @return {string}
*/
export const defangIPaddr = function (address) {
return address.replace(/\./g, '[.]')
}

View File

@ -0,0 +1,6 @@
import { defangIPaddr } from '../../src/string/defanging-an-ip-address'
test('IP地址无效化', () => {
expect(defangIPaddr('1.1.1.1')).toBe('1[.]1[.]1[.]1')
expect(defangIPaddr('255.100.50.0')).toBe('255[.]100[.]50[.]0')
})