• Sign Up
    Time to claim your honor
  • Training
  • Practice
    Complete challenging Kata to earn honor and ranks. Re-train to hone technique
  • Freestyle Sparring
    Take turns remixing and refactoring others code through Kumite
  • Community
  • Leaderboards
    Achieve honor and move up the global leaderboards
  • Chat
    Join our Discord server and chat with your fellow code warriors
  • Discussions
    View our Github Discussions board to discuss general Codewars topics
  • About
  • Docs
    Learn about all of the different aspects of Codewars
  • Blog
    Read the latest news from Codewars and the community
  • Log In
  • Sign Up
bhamscott Avatar
Name:Scott Blanchard
Clan:Unknown
Skills:css, javascript, html5, angular, typescript
Member Since:Jun 2023
Last Seen:Jun 2024
Profiles:
Following:0
Followers:0
Allies:0
View Profile Badges
  • Stats
  • Kata
  • Collections
  • Kumite
  • Social
  • Discourse
  • Conversations (24)
  • Replies
  • Authored
  • Needs Resolution
  • Custom User Avatar
    • XecellencWeb
    • commented on "Counting Duplicates" javascript solution
    • 2 years ago

    like seriously speaking me too. he's really clever

  • Custom User Avatar
    • Palillo10
    • commented on "Build Tower" kata
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "String ends with?" javascript solution
    • 2 years ago

    7kyu and there's a built in method?

  • Custom User Avatar
    • bhamscott
    • commented on "Counting Duplicates" javascript solution
    • 2 years ago

    The key is line 3. If we just wanted ALL matches, we could just return arr.indexOf(val) !== arr.lastIndexOf(val) as that gives us, for example, ALL duplicate occurrences of "b" or "i" or whatever in the array.

    However, the problem asks us to only return distinct duplicates, so we can't use the common pattern of indexOf !== lastIndexOf. We have to be a bit more clever than that.

    In order to filter down to a distinct duplicate of the current index item, we essentially just want to return the last occurrence of the duplicate. The filter has to skip over duplicate values that have already been matched and find the last one.

    Specifically we only want to return the current val in the filter/loop if (1) indexOf(val) has already appeared in the array but is not the current occurrence of val that we are looking at (arr.indexOf(val) !== i) AND (2) lastIndexOf(val) is the current occurrence (arr.lastIndexOf(val) === i).

  • Custom User Avatar
    • bhamscott
    • commented on "Counting Duplicates" javascript solution
    • 2 years ago

    In the words of Larry David, "pretty, pretty good". Very clever use of current index, indexOf() and lastIndexOf() to find the distinct duplicates. It took me some time to unpack the logic of the comparision but once I got it I realized how clever the technique here to resolve to the distinct duplicate items vs the collection of all of them.

  • Custom User Avatar
    • bhamscott
    • commented on "Counting Duplicates" javascript solution
    • 2 years ago

    I'm always looking for a way to use reduce and for the most obvious reduction challenges, its my goto, but I need to study this more to wrap my head around what's happening here. This takes reduction to a new level. I'd really like to use this pattern once I understand it.

  • Custom User Avatar
    • bhamscott
    • commented on "Anagram Detection" javascript solution
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "Find the unique number" kata
    • 2 years ago

    Same. This is by no means a 6kyu skill level challenge. The base solution here is a core fundamental javascript concept.

  • Custom User Avatar
    • bhamscott
    • commented on "Find the unique number" kata
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "Build Tower" kata
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "Playing with Sets : Symmetric difference" javascript solution
    • 2 years ago

    Thanks and noted on spoiler flag. Can you also share how you created the truth table? Looks like console.table output, which I also have not used but seems very useful.
    What does each row represent and why are there 4 of them (ie, what is the input that the table is reflecting)?

  • Custom User Avatar
    • Polymorbism
    • commented on "Playing with Sets : Symmetric difference" javascript solution
    • 2 years ago

    Please remember to use the spoiler flag, especially when posting your entire solution.

  • Custom User Avatar
    • bhamscott
    • commented on "Playing with Sets : Symmetric difference" javascript solution
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "Playing with Sets : Union" javascript solution
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar
    • bhamscott
    • commented on "Largest pair sum in array" javascript solution
    • 2 years ago

    This comment is hidden because it contains spoiler information about the solution

  • Loading more items...
  • © 2025 Codewars
  • About
  • API
  • Blog
  • Privacy
  • Terms
  • Code of Conduct
  • Contact

Confirm

  • Cancel
  • Confirm

Collect: undefined

Loading collection data...