Created
June 22, 2015 02:35
-
-
Save ionox0/dbd55f96c8f7180e89f5 to your computer and use it in GitHub Desktop.
inrhythm test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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