{"size": 813, "ext": "js", "max_stars_repo_path": "CodeWars/Scramblies.js", "max_stars_repo_name": "Nesci28/Algorithms", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "CodeWars/Scramblies.js", "max_issues_repo_name": "Nesci28/Algorithms", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "CodeWars/Scramblies.js", "max_forks_repo_name": "Nesci28/Algorithms", "max_forks_repo_forks_event_min_datetime": "2021-12-29T16:02:14.000Z", "max_forks_repo_forks_event_max_datetime": "2021-12-29T16:02:14.000Z"}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": 1, "avg_line_length": 27.1, "max_line_length": 150, "alphanum_fraction": 0.6666666667}
/* https://www.codewars.com/kata/55c04b4cc56a697bb0000048

Complete the function scramble(str1, str2) that returns true if a portion of str1 characters can be rearranged to match str2, otherwise returns false.

Notes:

Only lower case letters will be used (a-z). No punctuation or digits will be included.
Performance needs to be considered
Input strings s1 and s2 are null terminated.
Examples
scramble('rkqodlw', 'world') ==> True
scramble('cedewaraaossoqqyt', 'codewars') ==> True
scramble('katas', 'steak') ==> False

*/

function scramble(str1, str2) {
  let object = {}
  for (let i = 0; i < str1.length; i++) {
    object[str1[i]] = ++object[str1[i]] || 1
  }
  for (i = 0; i < str2.length; i++) {
    if (object[str2[i]]) {
      object[str2[i]]--
    } else {
      return false
    }
  }
  return true
}