Last active
April 22, 2017 17:03
-
-
Save daartv/4477b5b1ebb19069acaa1a100a80097b to your computer and use it in GitHub Desktop.
Frequency Sort and Is Subset Of
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
var frequencySort = function(s) { | |
var arr = s.split(''); | |
var obj = {}; | |
var results = []; | |
for (var i = 0; i < arr.length; i++) { | |
obj[arr[i]] = 0 | |
} | |
for (var j = 0; j < arr.length; j++) { | |
if (obj[arr[j]] !== undefined) { | |
obj[arr[j]]++; | |
} | |
} | |
var sorted = ''; | |
for (var key in obj) { | |
while (obj[key] > 0){ | |
results.push(key); | |
obj[key]--; | |
} | |
} | |
return obj; | |
}; |
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
var isSubsequence = function(s, t) { | |
let counter = 0; | |
for (let i = 0; i < s.length; i++) { | |
for (let j = 0; j < t.length; j++) { | |
if (s[i] === t[j]) { | |
counter++; | |
t = t.slice(j,t.length); | |
} | |
} | |
} | |
if (counter === s.length) { | |
return true; | |
} else { | |
return false; | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment