cssAudio - Activefile-genericCSS - ActiveGeneric - ActiveHTML - ActiveImage - ActiveJS - ActiveSVG - ActiveText - Activefile-genericVideo - ActiveLovehtmlicon-new-collectionicon-personicon-teamlog-outoctocatpop-outspinnerstartv

Pen Settings

CSS Base

Vendor Prefixing

Add External CSS

These stylesheets will be added in this order and before the code you write in the CSS editor. You can also add another Pen here, and it will pull the CSS from it. Try typing "font" or "ribbon" below.

Quick-add: + add another resource

Add External JavaScript

These scripts will run in this order and before the code in the JavaScript editor. You can also link to another Pen here, and it will run the JavaScript from it. Also try typing the name of any popular library.

Quick-add: + add another resource

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

            
              <div class="container">
  <h1>Aanagram Puzzle</h1>

<p>Check out your console to see it running.
</p>

<h3>Source</h3>
<pre><code class="lang-coffeescript">###
Problem: Given a list (array) of words, find all the possible anigrams in that list and return
a two deminitional array of the results.

Assumption: all the strings are valid words.
###

anagrams = (words) ->
  # Store as a map for each words.
  anagrams = {}
  # Create a new array of the sorted strings to use as the key in the array
  sorted = words.map (word) ->
    return word.split('').sort().join('')
  sorted.forEach((st, i) ->
    if (!anagrams.hasOwnProperty(st))
      anagrams[st] = [words[i]]
    else
      anagrams[st].push(words[i])
  )

  results = []
  for key, value of anagrams
    results.push value if value.length > 1
  
  return results


testWords = ['dell', 'ledl', 'abc', 'cba', 'will', 'not', 'match', 'these']
console.log(anagrams(testWords))
  </code>
</pre>
</div>
            
          
!
            
              ###
Problem: Given a list (array) of words, find all the possible anigrams in that list and return
a two deminitional array of the results.

Assumption: all the strings are valid words.
###

anagrams = (words) ->
  # Store as a map for each words.
  anagrams = {}
  # Create a new array of the sorted strings to use as the key in the array
  sorted = words.map (word) ->
    return word.split('').sort().join('')
  sorted.forEach((st, i) ->
    if (!anagrams.hasOwnProperty(st))
      anagrams[st] = [words[i]]
    else
      anagrams[st].push(words[i])
  )

  results = []
  for key, value of anagrams
    results.push value if value.length > 1
  
  return results


testWords = ['dell', 'ledl', 'abc', 'cba', 'will', 'not', 'match', 'these']
console.log(anagrams(testWords))

            
          
!
999px
Loading ..................

Console