Whether the query string already exists

Source: Internet
Author: User

On a website to cast a resume, the company has more than one to check, compare which companies have been cast, a little time,

Write a small query to find out if the ready delivery company is in the cast list:

<input type= "text" placeholder= "Please enter company name" id= "Companies"/>

<script type= "Text/javascript" >

function S (FN) {
Return fn.tostring (). Split (' \ n '). Slice (1,-1). Join (' \ n ') + ' \ n ';
}

var str=s (function () {
Fei Grouda
Asian Union
Ping An good room-important member of Ping an group
Safe, good car.
Ping An financial technology
Ocean Terminal
Only the product will
Delicious 77
Pun Shan Chau Club
Iqiyi Art
Site Navigation
UnionPay Business
Shentong Fish Fish Information
Easy Media
ePRO Payment
Are you hungry?
Housing
Day loan
Cool Fun
Medium and software
Schneider
Lou Kou E-commerce
Investing in the people's Treasure
Beep, beep.
Elf Net
Sohu Group
Oriental Wealth
Room Shanghai Research and Development Center
Tradehero
Darbond
Volkswagen Reviews Web
Easy Jump Move
New Real Digital
Pat Loan
ping++
Ndpmedia
Takeaway Superman
Cool Fun
What doing}),
Arr=str.replace (/^\s+|\s+$/g, "). Replace (/\S+/GM," "). Split (" ");

var companyinput=document.queryselector ("#company");
Companyinput.onblur=function () {
var txt=companyinput.value.replace (/^\s+|\s+$/g, "). Replace (/\S+/GM," "),
Len=arr.length,
Max=math.ceil (LEN/2);


Console.time ("Timmer1");
for (var i=0; i<len; i++) {
if (arr[i]==txt) {
Console.log (TXT);
Break
}
}
Console.timeend ("Timmer1");

Console.time ("Timmer");
for (var i=0;i<max; i++) {
if (arr[len-i]==txt| | Arr[i]==txt) {
Console.log (TXT);
Break
}
}
Console.timeend ("Timmer");
}

Would like to make the query a little faster, take half the length, the end of the same time contrast, test down, so slower

Whether the query string already exists

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.