Recently, I have to solve code problems while searching for job opportunities.
It gave me an array of numbers such as
and told me to find what to do.
It was not so difficult after all. But I thought it would be great to learn language concepts.
[Table of Contents]
- What to do?
- Vice Versa(char to numbers)
- Don’t repeat yourself with functions
1. What to do?
I thought that I should get some url to reach the next proccess. So I assumed that I have to turn those numbers in characters.
First, I remembered that each numbers and characters have its own counterparts. So I need to tweak every numbers to corresponding characters.
Then, I have to join them into entire url not to type them manually.
So let’s wrtie some code for that.
You may code with your browser console by
ctrl + shift + i or your code editor such as Visual Studio Code etc.
The above code snippet shows that those numbers were actually a link to some url.
We just made computer to tweak each number in array with
map keyword and
String.fromCharCode(x) after fat arrow to turn each number to a corresponding character.
Now we figured out where to go. It was https://www.medium.com.
But we wouldn’t want to type each character to do so.
We have to make them into string to easily copy and paste.
So the next phase is to join the array of each chracters to string.
and now we got url “https://medium.com” and easily go to the next phase.
3. Vice Versa(Characters to numbers)
Now You got what you wanted, but It is good to know how to do things oppositely at the same time.
Who knows that you would be a recruiter who needs to hire some developers?
Because you already know what matters here, I will include entire code snippets below.
You just need to know that we need codes what do exactly opposite things from the previous example.
split and charCodeAt .
You may write code snippet like the example below.
4. Don’t repeat yourself with functions
Now You know everything I wanted to write for this article.
But It would be unefficient if you have to type those long words each time.
So you may save those process using fucntions.
When you make functiosn to do, You don’t have to repeat what you already know. You just pass the string “https://medium.com” as arguments and that is all.
I want to point out that it is alway better to simple type annotation as I did with
(str = "") to help others and computer to understand what happens.
You may make function for decode yourself.
You did well. I hope this article helped you to learn how to turn numbers into characters and vice versa. You may let comments if there are parts not explained well or not correct.
Thanks for reading and please share this post.
- Did you like my coding style? Work with me. Please, send messages via LinkedIn.
- I am also developing React FrontEnd and Rust BackEnd Website www.steadylearner.com It lacks content but I would write it again together with real posts written here.
I am not a native English speaker. When some words don’t make sense, grammar problems etc. Please leave a comment below. I will read this post again and edit them right away.