Skip to content

Instantly share code, notes, and snippets.

@ionox0
Created June 22, 2015 02:35
Show Gist options
  • Save ionox0/dbd55f96c8f7180e89f5 to your computer and use it in GitHub Desktop.
Save ionox0/dbd55f96c8f7180e89f5 to your computer and use it in GitHub Desktop.
inrhythm test
/*
Array One Array Two Result
["a"] ["a"] => True
["ab"] ["ac"] => False
["aa"] ["ab"] => False
["cbb"] ["abbc"] => True
["abbccdd"] ["abbcccdd"] => True
*/
function check(a, b){
var c = {};
for (var i = 0; i < a.length; i++){
if (c[a[i]] === undefined) c[a[i]] = 1;
else c[a[i]]++;
};
var d = {};
for (var i = 0; i < b.length; i++){
if (d[b[i]] === undefined) d[b[i]] = 1;
else d[b[i]]++;
};
for (prop in c){
if (!c.hasOwnProperty(prop)) continue;
if (d[prop] < c[prop] || d[prop] === undefined) {
console.log('false')
return;
}
};
console.log('true');
}
check(['a', 'b'], ['a', 'b']);
check(['a', 'a', 'b'], ['a', 'a', 'a', 'b']);
check([], ['a', 'b']);
check(['a'], []);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment