ExpressJS
Again, today we were hit with another recursion problem that was really difficult. Although in my opinion it was easier than yesterday's. The problem is to take a string (like 'abc') and return an array that lists all the combinations (['abc','acb','bac','bca','cab','cba']). It was a similar format to yesterday's, except the return array consists of all combination of the str. In yesterday's case, the substring that is being pushed into the array has an order (i.e. a cannot be after b etc.) but the length doesn't matter (can be 'a', can be 'ab' can be 'abc'). In today's problem, the length does matter, as the substrings that is being pushed into the array must be of the same length of the str that is taken in as a parameter. And also, the order doesn't matter (str of abc can return 'bac'). I tried doing the problem without recursion and I hit a problem; depending on the length of the string, thats how many for loops there must be to rearrange all the characters. The first for loop holds the index of one of the characters, the second for loop holds the second index and the last for loop rearranges the last index. Now if the string was 4 character, then it would be 4 for loops. I was thinking of doing a recursion inside a for loop since even a recursion would have limits, but I still couldn't find a solution. The answer key, as it turns out has a recursion inside the for loop so my mentality was right but I couldn't implement it in code.
We did ExpressJS today and one of the exciting parts of using Express is the ability to use sockets. Sockets allow a non-blocking connection between the server and the user. All group chats and video games undergoes that kind of methodology. Anything that happens to the server is reflected to every single user in real time. One of the annoying things about Express is all the modules you have to install to make the program work. Sockets is confusing in the sense that every event that you fire from client to server or server to client, you have to write a listener function to that event on the opposite side.
- Client-side emits handle to Server-side's listener which emits a function to the Client-side's listener for that specific server side function.
No comments:
Post a Comment