Giter VIP home page Giter VIP logo

Comments (8)

varjmes avatar varjmes commented on May 24, 2024

Tweeting about this from @yourfirspr at 3PM (GMT), this is a great issue and exactly the kind of thing I want. Great balance between not giving the answer, but guiding you on your way.

👌

from initials.

Ketouem avatar Ketouem commented on May 24, 2024

Just to get a bit of context, what is t.plan used for ?

from initials.

gr2m avatar gr2m commented on May 24, 2024

@Ketouem t.plan is part of https://www.npmjs.com/package/tape, see https://www.npmjs.com/package/tape#t-plan-n. You define the amount of tests (assertions), which is especially useful if you do async tests. Here we could remove t.plan and put t.end to the very end, it would have the same effect

from initials.

sylvesterwillis avatar sylvesterwillis commented on May 24, 2024

On line 177 of initials.js, there is a call to Array.splice inside of the loop which removes elements inside of the possibleInitials array causing the loop to skip some items. If we run the loop from end to beginning this issue is resolved, but the output of initials(['Moe Min', 'Moe Minutes']) becomes ["Moe Min", "MMinutes"] which is different than the expected value of the current test. Would you rather go with this approach and edit the test accordingly or keep tackling it to get an output that matches the current test?

from initials.

gr2m avatar gr2m commented on May 24, 2024

@sylvesterwillis good idea with running backwards! But Moe Min is not really helpful as initials for Moe Min, but maybe your changes is progress in the right direction? Wanna start a pull request, and we discuss there?

from initials.

sylvesterwillis avatar sylvesterwillis commented on May 24, 2024

Sure, I'll be on the train for a bit but will be able to talk more in about ~2hrs or so. My PR doesn't include any changes to the test since we'll be talking more about it.

from initials.

gr2m avatar gr2m commented on May 24, 2024

I think one way to approach the problem is that instead of ignoring initials that might be valid for both entirely, we could only allow them once.

For example, for simpler debugging, add only this test at the very end to the test/initials-test.js file:

test.only('debug', function (t) {
  t.deepEqual(initials(['Moe Minutes', 'Moe Min']), ['MoM', 'MMi'], '["Moe Minutes", "Moe Min"] ☛ ["MoM", "MMi"]')
})

then in initials.js, log initialsForNamesMap in line 170, before the // initialsForNamesMap comment, then run

node test/initials-test.js

The output will look something like this:

TAP version 13
# debug
{ 'Moe Minutes': [ 'MM' ], 'Moe Min': [ 'MM' ] }
{ 'Moe Minutes': [ 'MoM', 'MMi' ], 'Moe Min': [ 'MoM', 'MMi' ] }
{ 'Moe Minutes': [ 'MoMi', 'MoeM', 'MMin' ],
  'Moe Min': [ 'MoeM', 'MMin', 'MoMi' ] }
{ 'Moe Minutes': [ 'MMinu', 'MoeMi', 'MoMin' ],
  'Moe Min': [ 'MoMin', 'MoeMi' ] }
{ 'Moe Minutes': [ 'MoMinu', 'MoeMin', 'MMinut' ],
  'Moe Min': [ 'MoeMin' ] }
{ 'Moe Minutes': [ 'MoeMinu', 'MMinute', 'MoMinut' ],
  'Moe Min': [] }
{ 'Moe Minutes': [ 'MMinutes', 'MoeMinut', 'MoMinute' ],
  'Moe Min': [ 'Moe Min' ] }
not ok 1 ["Moe Minutes", "Moe Min"] ☛ ["MoM", "MMi"]

If we'd check for the amount of possible different initials, we could end with

{ 'Moe Minutes': [ 'MoM', 'MMi' ], 'Moe Min': [ 'MoM', 'MMi' ] }

And give Moe Minutes the initials MoM, and Moe Min the initials MMi. I guess for that we would need to add an extra check before these lines

I think there are different ways to achieve that, it's quite a puzzle though. I'm looking forward to see what we'll come up with

from initials.

gr2m avatar gr2m commented on May 24, 2024

resolved via #16, thanks @javimolla & @Charlotteis ✌️

from initials.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.