Skip to content

Instantly share code, notes, and snippets.

@ukayani
Last active Sep 10, 2020
Embed
What would you like to do?
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