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 8798465
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T00:06:11+00:00 2026-06-14T00:06:11+00:00

I have created a game that is based on a grid being populated with

  • 0

I have created a game that is based on a grid being populated with words

In my code I have a small bit of underscore.js that helps my words fit in the space available in the grid without breaching the grids barriers.

I understand that it is very powerful java script and don’t personally have a problem with it. But my team manager would like to get rid of it for some jQuery that will provide the same solution as there is only one function and would save me having a whole library. How I would replace this with some jQuery?

function getWordToFitIn(spaceAvail, wordlist) {
    var foundIndex = -1;
    var answer = _.find(wordlist, function (word, index) {
        if (word.length <= spaceAvail) {
            foundIndex = index;
            return true;
        }
    });
    if (foundIndex == -1) {
        answer = getXSpaces(spaceAvail);
        _.find(wordlist, function (word, index) {
            if (word[0] == " ") {
                foundIndex = index;
                return true;
            }
        });
    }
    if (foundIndex != -1) {
        wordlist.splice(foundIndex, 1);
    }
    return answer;
}
  • 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-14T00:06:12+00:00Added an answer on June 14, 2026 at 12:06 am

    As far as I can see, the only underscore method youre using is _.find. But I don’t think you are using it as it was intended. It looks like you are simply looping and returning true when a criteria is met.

    You can use the native forEach if you don’t have legacy support, or use a shim. Or you can use the jQuery.each method.

    The first loop could probably (I’m not 100% sure about the answer variable) be written like this:

    var answer;
    $.each(wordlist, function(index, word) {
        if (word.length <= spaceAvail) {
            foundIndex = index;
            answer = word;
            return false; // stops the loop
        }
    });
    

    And the second one:

    $.each(wordlist, function (index, word) {
        if (word[0] == " ") {
            foundIndex = index;
            return false;
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created a hangman based on a jQuery code that I found online.
All, I am trying to code a Connect4 game. For this, I have created
Suppose I have an component based game engine, and in that engine I have
We have several game servers that produces events based on player actions. We want
I recently created a turn-based game server that can accept 10s of thousands of
I have a big 3d game that lets players build and create interesting and
I have created a game where the user can upload their high score and
I have created an animated game app, In which I am using NSTimer to
I have created a Space Invaders Game using an example game + source. Using
I am writing a game which uses opengles. I have created my renderer class

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.