Skip to content

patgarcia/ransome-note

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 

Repository files navigation

ransome-note

Ransome note problem

function ransomAvail(note, magazine) {
  const magFreqs = freqCounter(magazine);
  const noteFreqs = freqCounter(note);
  for (let [char, freq] of noteFreqs) {
    if (magFreqs.has(char)) {
      const magCharFreq = magFreqs.get(char);
      if (magCharFreq < freq) return false;
    }
  }
  return true;
}

function freqCounter(str) {
  return Array.from(str).reduce((map, letter) => {
    if (letter !== " ") {
      map.set(letter, (map.get(letter) || 0) + 1);
    }
    return map;
  }, new Map());
}

About

Ransome note problem

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published