Skip to main content

Posts

Showing posts from March, 2015

Health: Stomach Ulcer and Food Poisoning Quick Treatment

First of all, I'm not a medical doctor. I have an engineering degree in low power electrical field and I am a web developer 😶 But I do have lots of experiences handling these: stomach ulcer and food poisoning ; for myself and for other people around me. Let me share some of quick treatments for stomach ulcer and food poisoning . Stomach Ulcer: The Habit Sometimes, or most of the time, as we get older, we do not take meal with constant periodical cycle like while we were children or teens. But as I've noticed nowadays, teens also have that habit . Our human body can adapt, if you notice, to that kind of punishment . At first, it was probably hurt like insane, but as time went by, we don't feel the pain. It has multiple meanings: Our nerves finally ignore the pain signal because we consciously and constantly pretend it did not hurt like Rambo bit, but our system hasn't actually adapted. This one is dangerous ⚠️ The...

JavaScript: Shuffling Array Elements

Shuffle is different than random in term. But indeed randomness is applied in shuffling . As in shuffling cards and giving out one random card, those are different. Algorithmically , we can loop through the reference array, generate random index based on the reference array length, then put that item (with that random index) to a new array. But since random can generate similar number (being floored or rounded down) as previous one, that can lead to duplicates . For example We have an array: ["a", "b", "c", "d"] Then loop through it while blindly creating a random index to copy the randomly chosen item to a new array, surely there will be duplicates. Unwanted output: ["c", "a", "a", "d"] ["d", "b", "b", "b"] ["a", "a", "c", "a"] Deletion We need to trim the array reference after one element gets ...

JavaScript: Object Literal Pairs Basic Sorting (Number and Letter)

In JavaScript, there's sort([compareFunction]) method that we can utilize to sort an array. By default, if we do not provide the comparing function, just sort() , the sorting will be based on the input strings given. Read more at Mozilla Developers Network documentation. Let's get right on it For instance, we have this object literal pairs: var a = { "C_twenty" : 20, "B_six" : 6, "D_threeHundred" : 300, "A_ten" : 10, "E_minusEightOne" : -81, "F_eightyPointSix": 80.6 }; We cannot sort those [property]: [value] pairs directly. There's no direct built-in method in JavaScript for that (yet). We need to convert the object into an array first, then we can sort it. I typed a basic application (in JavaScript) to sort the object input by number or letter. In this example, there are two options for the function...