48. E-mail string judge
topic Link
https://www.nowcoder.com/practice/c72b2b5472704d4a98597cb74b0257a7?tpId=2&&tqId=10859&rp=1&ru=/activity/oj&qru=/ta/front-end/question-ranking
subject description
to determine whether the input correct mailbox format
input described
mailbox string
output descriptor
true that a correct format
key technology
regex
Title analysis
mailbox regular expression: ^ \ w + ([-. w +) * \ \ w
function isAvailableEmail(sEmail) { var reg = /^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/; return reg.test(sEmail); }
49. The character string statistical
topic Link
https://www.nowcoder.com/practice/777d0cd160de485cae0b1fd1dd973b44?tpId=2&&tqId=10862&rp=2&ru=/activity/oj&qru=/ta/front-end/question-ranking
Title Description
- Statistical frequency of occurrence of each character string, returns an Object, key statistics for the character, value for the frequency of occurrence
- Without limiting the order key
- Parameter input string is not empty
- Ignore whitespace characters
Example 1
Input
'hello world'
output
{h: 1, e: 1 , l: 3, o: 2, w: 1, r: 1, d: 1}
The key technology
string
Topic analysis
- Res defined objects.
- Determining whether the character is a space;
- If it were not spaces, to determine whether there is a character in the res object;
- If not, add the attribute res target, while a value of 1;
- If present, this object is res 1 attribute values.
function count(str) { var res = {}; for(var i=0;i<str.length;i++){ if(str[i] != ' '){ if(!(str[i] in res)){ res[str[i]] = 1; }else{ res[str[i]]++; } } } return res; }