删除两个字符串中不存在的字符
我有两个字符串,一个是一个可以更改的掩码,另一个是用户输入。
我需要保持口罩格式并删除我有两个字符串中不
rawValue: "25155122"
value: "2 5155 1220 0000"
的
newValue = "2 5155 122" <=
the zeros are removed as they are a mask and user has not typed in the rest of the numbers yet
存在
const strSet = str => new Set(str.split(''));
const setDiff = (a, b) => new Set(Array.from(a).filter(item => !b.has(item)));
const prune = (str, set) => str.split('').filter(x => set.has(x))
.join('');
const diff = setDiff(strSet(rawValue), strSet(value));
const a1 = prune(value, diff);
const b1 = prune(rawValue, diff);
数字
I have two strings, one is a mask which can change and the other one is a users input.
I need to keep the mask format and remove numbers that are not present in both strings
rawValue: "25155122"
value: "2 5155 1220 0000"
I have for example these two strings, the expected outcome would be this:
newValue = "2 5155 122" <=
the zeros are removed as they are a mask and user has not typed in the rest of the numbers yet
This is what i've tried so far:
const strSet = str => new Set(str.split(''));
const setDiff = (a, b) => new Set(Array.from(a).filter(item => !b.has(item)));
const prune = (str, set) => str.split('').filter(x => set.has(x))
.join('');
const diff = setDiff(strSet(rawValue), strSet(value));
const a1 = prune(value, diff);
const b1 = prune(rawValue, diff);
Thanks for the help in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不确定您到底想要什么,但希望这能解决您的问题...
Not certainly sure what exactly you want, but hopefully this resolves your issue...