Skip to content

Instantly share code, notes, and snippets.

@ukayani
Last active September 10, 2020 13:20
Show Gist options
  • Save ukayani/eb3890bdd442d96954d3908939a103d8 to your computer and use it in GitHub Desktop.
Save ukayani/eb3890bdd442d96954d3908939a103d8 to your computer and use it in GitHub Desktop.
test.js
//exercise 1
function toLeet(input) {
let leet = {
a: "4",
A: "4",
e: "3",
E: "3",
i: "1",
I: "1",
o: "0",
O: "0",
s: "5",
S: "5",
t: "7",
T: "7",
b: "5",
D: "5" // Not sure if this was a typo and meant B
};
return input.replace(/[aAeEoOsStTbBD]/gi, m => leet[m]);
}
//exercise 2
function frequencyList(input) {
return input.replace(/(.)\1*/g, function(strs, i) {
//returns the character + the number of times matched
return i + strs.length;
});
}
// test cases
console.assert(toLeet('Let's have some fun.') == 'L37\'5 h4v3 50m3 fun.');
// .. more for toLeet
console.assert(frequencyList('aaabbdcccccf') == 'a3b2d1c5f1');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment