Sets, multiple types of loops, and more

When JavaScript arrays contain primitive values (strings, numbers, undefined, null, booleans, and symbols), there might be cases in which you’re wanting to detect if the array contains any duplicated elements.

In other words, you would want to determine if elements in the array are unique. There are several approaches you can take to achieve this.

Let’s take a closer look at our options.

Approach 1. Nested Loops

In this approach, we will traverse the array, starting from the first element and for each element, we will compare this element to all the other elements to see if there is a match.

To achieve this…


React hooks help with carrying stateful logic and keeping their lifecycle separate from the view layer lifecycle. They’ve been around since React v16.8 and since people have been avoiding class components in favor of hooks.

One of the somewhat interesting aspects of hooks is their flexibility in terms of composition and abstraction. If a code snippet using different built-in hooks is handling a part of logic that is separate and independent from other parts, it can be abstracted away as a Custom Hook.

useBackButton custom hook

To handle the behavior of hardware back button in Android and tvOS devices using React Native, there…


Image for post
Image for post

Not all the components you write for your React application can be divided into Stateful and Stateless (dumb) categories. There is a 3rd advanced type of component in React called a higher-order component. A higher-order component is a function that takes a component as an argument and returns another component. Check out my other article to see how higher-order components are used in the real world.

Creating a HOC with Tests

We’ll be using Enzyme and Jest, but these concepts apply to any testing library.

One of the common HOCs I write for every project of mine is called withConditional.


Image for post
Image for post
Clone!

Cloning an object in JavaScript a task that is almost always used in any project, to clone everything from simple objects to the most complicated ones.

As it may seem simple for not seasoned JavaScript developers, it actually has some pitfalls that would hurt you in the bones if you didn’t know the proper way to do it.

Talk is cheap, show me the code

The first way that could cross a developer’s mind is to deeply iterate through a source object’s properties and copy them one by one on the target object. …


Image for post
Image for post
Higher Order Components in React

Before you read this article, read React’s official document on HOCs if you haven’t read it yet.

Pretty much in any React application, you call an API to fetch some data and use them to render some content in your application.
Since UI components need to show some kind of progress bar, loading indicator, etc to tell users that data is being fetched, it may be cumbersome to implement loading logic in every single component and to pass a loading property from your redux store or your local state to child components. …


javascript is different from other languages. Programmers from other languages once entering the javascript era might get confused easily but the action is not true on the reverse side. One of the easy to get yet hard to implement and maintain task in Javascript is to perform an async task.

To asynchronously run a task in Javascript, Developers have 3 different options.
1. Callbacks (ES5)
2. Promises (ES6)
3. Async / Await (ES7: still draft)

In this article we are going to cover the first 2 options yet leaving the third one to the audience, probably lots of snippets and…


Fair warning: This solution worked for the certain use case explained in the article back in 2016, the same date this very article was published. It might not work right now!

There are many cases iframe would be a good solution to use. Although they are kind of dead to HTML and not a lot of developers use it, It could come up to you as a solution to a complicated problem some day.

Knowing a way to communicate through an iframe to parent is such a valuable and time saver. Maybe iframe could tell it’s parents when it’s content…

Farzad YZ

Senior Software Engineer @epicgames . formerly @futurice . Javascript, Typescript, React(native), International speaker. UI engineering, Statecharts, Reactivity

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