IP地址无效化
This commit is contained in:
parent
34a76e22b9
commit
32fd589c3f
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -2,10 +2,13 @@
|
||||
"cSpell.words": [
|
||||
"Gitpod",
|
||||
"LVIII",
|
||||
"Paddr",
|
||||
"Prinme",
|
||||
"abcdefg",
|
||||
"cdefgab",
|
||||
"chuan",
|
||||
"defang",
|
||||
"defanging",
|
||||
"dvdf",
|
||||
"lcci",
|
||||
"lcof",
|
||||
|
@ -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)
|
||||
|
7
src/string/defanging-an-ip-address.js
Normal file
7
src/string/defanging-an-ip-address.js
Normal file
@ -0,0 +1,7 @@
|
||||
/**
|
||||
* @param {string} address
|
||||
* @return {string}
|
||||
*/
|
||||
export const defangIPaddr = function (address) {
|
||||
return address.replace(/\./g, '[.]')
|
||||
}
|
6
test/string/defanging-an-ip-address.test.js
Normal file
6
test/string/defanging-an-ip-address.test.js
Normal 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')
|
||||
})
|
Loading…
Reference in New Issue
Block a user