Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4094320
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T19:43:48+00:00 2026-05-20T19:43:48+00:00

I have a function that corrects capitalization for a list of unusually capitalized words:

  • 0

I have a function that corrects capitalization for a list of unusually capitalized words:

var line = "some long string of text";
["AppleScript", "Bluetooth", "DivX", "FireWire", "GarageBand", 
 "iPhone", "iTunes", "iWeb", "iWork", "JavaScript", "jQuery", "MacBook", 
 "MySQL", "PowerBook", "PowerPoint", "QuickTime", "TextEdit", "TextMate",
 // ... 
 "Wi-Fi", "Xcode", "Xserve", "XMLHttpRequest"].forEach(function(name) {
      line = line.replace(RegExp(name, "gi"), name);
});

Now the problem I am facing is that most input strings will contain on average between 0 and 3 of these words. Obviously now I am doing dozens (and potentially hundreds; that array has an uncanny tendency to grow over time) of function calls which essentially do nothing.

How can I make this code faster and get rid of the unnecessary function calls?

Example input:

My iphone application has a user form under UIViewController. When I start application again some of my UIView changes its positions and sizes. (These UIViews depend on keyboard position) Somewhere is definitely my fault. I try to figure what is going on when application starts again from background and where the UIView changes can be done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T19:43:49+00:00Added an answer on May 20, 2026 at 7:43 pm

    You can build regexp containing all your words, capturing each word by enclosing it in parentheses. Using that in a replace will provide enough information to recover the original word in the replace function.

      function correct (text, words) {
        return text.replace (RegExp ('\\b(?:(' + words.join (')|(') + '))\\b', 'ig'), function (m) {
          for (var a = arguments.length - 2; a--;)
            if (arguments[a])
          return words[a-1] || m;
        });
      } 
    
      console.log (correct ("My iphone itunes divx firewire application has a user form under uiviewcontroller. When I start application again some of my uiview changes its positions and sizes. (These uiviews depend on keyboard position) Somewhere is definitely my fault. I try to figure what is going on when application starts again from background and where the uiview changes can be done.",
        ["AppleScript", "Bluetooth", "DivX", "FireWire", "GarageBand", 
     "iPhone", "iTunes", "iWeb", "iWork", "JavaScript", "jQuery", "MacBook", 
     "MySQL", "PowerBook", "PowerPoint", "QuickTime", "TextEdit", "TextMate",
     // ... 
     "UIViewController","UIView",
     "Wi-Fi", "Xcode", "Xserve", "XMLHttpRequest"]));
    My iPhone iTunes DivX FireWire application has a user form under UIViewController. When I start application again some of my UIView changes its positions and sizes. (These UIViews depend on keyboard position) Somewhere is definitely my fault. I try to figure what is going on when application starts again from background and where the UIView changes can be done.
    

    This turns out to be faster then the original code.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a function that searches a string in a list of lists then
I have a function that I use to validate the contents of some text
I have a function that gets x(a value) and xs(a list) and removes all
I have a function that performs a hierarchical clustering on a list of input
I have this function that seems to be doing what it should: var getData
I have a function that needs to remove leading whitespace from a string. For
I have a function that taking (int * int list) list to a boolean
I have a function that needs quite some internal temporary storage for its computations
I have a function that returns me a date string using Zend_Date . $date
I have an third part dll that have a function that returns a string.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.