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

  • Home
  • SEARCH
  • 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 7805399
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T02:12:50+00:00 2026-06-02T02:12:50+00:00

I’m looking for the best solution here, i’ve got an idea but thinking it

  • 0

I’m looking for the best solution here, i’ve got an idea but thinking it could be done prettier.

I’m making an simple weather application. And i’m using Yahoo Weather api were they have got codes for weather conditions.

Depending on the condition i’m giving a code. Now, there are 50 codes and i’ve categorised them into 5 categories. In my case ex. my categori Snow contains 15 of Yahoo’s condition codes.

Well, if you got a better idea (which i bet there is) be free to suggest.

My thought is to return the matching value from a set of arrays, but not shure how to do it.

My code now looks like this:

function getCondition(code) {
   var snow = [1, 2, 3],
       sun = [4, 5, 6];
} 

What i need is the variable name that contains the matching number of the code?

I’ve made a JS-Fiddle
http://jsfiddle.net/BH8r6/

  • 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-06-02T02:12:52+00:00Added an answer on June 2, 2026 at 2:12 am

    Why dont you try an associative array when your key is your variable name and your values is the corresponding code for the variable name, thus your code will be something like this:

    var myCodeArray=[];
    
    myCodeArray["snow"]=[1, 2, 3];
    
    myCodeArray["sun"] = [4, 5, 6];
    

    now your method getCondition will be

    function getCondition(code) 
    {
        for(var definedCodeName in myCodeArray)
        {
          if(myCodeArray.hasOwnProperty(definedCodeName))
          {          
            var array=myCodeArray[definedCodeName ];
            for(var i=0;i<array.length;i++)
            {
                if(array[i]==code){
                    return definedCodeName ;}
            }
          }
        }
        return "Not found";
    }
    

    Demo

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

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I am doing a simple coin flipping experiment for class that involves flipping a

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.