Sign in

Let’s get straight to the point. The problem that I was trying to solve is as follows:

Given a random date time string, such as “2021/07/31 07:01:02” in the time zone of “Asia/Shanghai”, please convert it to equivalent date time in the time zone of “America/Los_Angeles”, with the format of “MM/DD/YYYY HH:mm:ss”.

Before we get started, here is what you need to know:

Objective: I want a function that looks like this:

function tz2tzConverter (originalDateTimeString, originalTZ, toTZ, toFormat){    return my new date time;
}

I am not sure how others…


How to Generate Awesome SVG Icons for Free

As a full stack developer, you wear many hats at once. It’s not absolutely necessary to be an expert at everything throughout the software development process, but you should be able to handle things correctly, quickly, and inexpensively.

One of those things is: LOGO design.

Typically, the first step to developing a website is to create a logo. You can easily and cheaply get a decent SVG logo even if you are not a graphic designer.

Here is how.

Step2: Create your logo here: https://app.brandmark.io/v3/

Step2: You can copy the svg by toggling your browser’s developer panel

Step3: You can create a svg file by pasting what you’ve copied into your editor

Step4: Using https://svgcrop.com/, remove the blank spaces around the logo

Step5: Convert the svg code to a react jsx component using this tool: https://svg2jsx.com/

Step 6: You now have it!


If you live in a country with limited access to the internet, and you happen to be a programer like I am, you may encounter the subject error message.

What this means is that you are unable to access the resources, namely the package that you are attempting to download locally.

Using a VPN may seem like an easy fix, but terminals, such as bash and powershell, do not work as well with VPN. In addition, even if you are able to route your traffic, chances are you will be blocked because of how GREAT the firewall is.

As a result, we have other options, such as setting your npm origin to mirror sites in your country, or mirrors that are not blocked.

However, I don’t want to go…


If you use browser to POST requests to your google cloud functions, most likely, you will run into the CORS error.

The error is caused by your browser, which is…


I would like to point out some terminology before we begin:

1. SSG: Static Site Generator

2. SSR: Server Side Rendering

3. ISR: Incremental Server Rendering

4. CSR: Client Side Rendering

Table representation

Visual representation


Direction: Flatten an array [1, 2, 3, 4, [3, 4, [4, 6]]]

Solution: recursion

const a=[1, 2, 3, 4, [3, 4, [4, 6]]];const re=[];function isFlat(arr){  let…

Problem: For any given array, resort or reorder the elments randomly.

Solution 1: using .sort()

Before we begin, let’s look at what happens inside .sort()

const arr=[1,2,3,4,5];
arr.sort((a,b)=>{
console.log(a,b)
if(a==2){
return a-b;
}else{
return b-a;
}
})
console.log(arr);
2, 1
3, 2
3, 2
3, 1
4, 1
4, 3
5, 1
5, 3
5, 4
[5, 4, 3, 1, 2]

As you can see: it is a loop, you can control the loop logic by using return a-b or b-a.

const arr=[1,2,3,4,5];function getRandom(array){
return array.sort((a,b)=>{
return Math.random()> 0.5? a-b:b-a;
})
}
console.log(getRandom(arr))

Solution 2: using recursion

Step1: create…


Direction: Count the number of occurrences of a character or substring in a string.

Example: substring of ‘ab’ in ‘ababcd’ is 2.

Solution: Recursion

Just to refresh your memory, here…


Direction: How to remove the last char appeared in a sentence.

Example: Remove last “n” from “How to remove the last empty space in a sentence.” beomes “How to remove the last empty space in a sentece.”

Solution 1:

let s="Hello, wold";String.prototype.reverse= function () {
return this.split('').reverse().join('');

}
String.prototype.removeFirst=function (c){
return this.replace(c,'');
}
s=s.reverse();
s=s.removeFirst('l');
s=s.reverse();
console.log(s)
//"Hello, wod"

Solution 2:

let s="Hello, wolld";function removeLast(str, c){
const arr=s.split(c);

const newString=arr.reduce((a, v, i, r)=>{
if( i === (r.length-1)){…

FRANK GO

coder, founder and explorer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store