【发布时间】:2020-07-11 20:22:43
【问题描述】:
const s1 = 'testuser1122@abc.com';
const s2 = 'testuser112@abc.com';
// some function
someFunction(s1, s2); // this should return 2->12 (character->position)
我需要从第二个字符串中找到缺失的字符。
代码应该在 ES6 中
【问题讨论】:
-
我喜欢@random 的回答,这对于我分享的代码来说已经足够了,但是考虑下面的用例, 有一个输入文本字段,其中用户输入
aaaa如果用户尝试删除第一个a那么我不应该将索引返回为3,但它应该是第一个索引,同样。 -
确保您的答案也适用于类似的输入,` const s1 = 'test1122@abc.com'; const s2 = 'test5678@abc.com';`
标签: javascript string ecmascript-6 string-matching