Hi y'all! Below are my most recent discovery of some string and array manipulation methods! I stumbled upon these methods while I was working through my daily algos. I can't pass up the chance to share what I learned! So, here it goes!
Static string method. Can't be used for a string object you created. Can be used for symbol matching
String.fromCodePoint(9731) - '☃' (_Yes I think it's a snowman too_)
You're maybe wondering how would you know which code point to use on the method beforehand. This is it!
This method returns a integer(non-negative) that is UTF-16 code point value. Takes in the index/position of the character from the string you want to know the code point value of.
Yes! It pads the end of the string to reach the length you indicated in the argument.
let str = "Yup" console.log(str.padEnd(8)+ "*") // Yup *
It can also take in a 2nd argument if you have a specific character or string to repeatedly pad your object.
let str = "Yup" console.log(str.padEnd(8, ".")+ "!") // Yup.....!
Same principle goes for padStart()
Removes whitespaces from both ends of the string. While trimEnd and trimStart removes whitespaces from a specific side of the string.
You maybe wondering in what algorithm was I able to use some of these methods?
Try and see if you can solve this Codewars Credit card mask challenge using some of the methods above!
Another one you can try is from CodeSignal, called Frame Generator. The goal is to write a function that takes in a number and returns an array of strings that would look like frame of asterisks.
Hope this is trivial! Until the next!