Posts

Showing posts from January, 2019

Fixing : An unexpected error occurred:latmap-stream/-/flatmap-stream-

Hello All, As you come on this page then I am sure that you got the following error while running yarn install An unexpected error occurred: "https://registry.yarnpkg.com/flatmap-stream/-/flatmap-stream-0.1.1.tgz: Request failed \"404 Not Found\"". This is not a yarn bug, it's due to the removal of the malicious code in the flatmap package used to steal bitcoin funds from Copay wallets. The fix is to find any packages that depend on and event-stream update them. In my case it was, nodemon and the most recent update removes the event-stream dependency. So you can do the following steps to fix this: Go into yarn global folder: cd ~/.config/yarn/global/ (or wherever yarn global files present) Search for  flatmap-  in current folder:  grep -R flatmap-* ./ Manually and recursively remove all folders that contain it, e.g.:  rm -rf ./node_modules/flatmap-stream ./node_modules/event-stream , etc. Now remove above modules from the current pro...

Mastering in Javascript | get size of json object

Image
Mastering in Javascript: As a JavaScript developer, we have to handle multiple conditions with objects to match our requirements. So sometimes we need to find the length of the object. Get the size of JSON object: To get the size of an array we use array.length but for the object, it won't work, let's see it by example. var arrObj = { 'first_name' : 'Vikas' , 'last_name:' : 'Kad' , 'age' : 26 } The output will be like this: If you see output arrObj.length shows undefined    To find the size of object we will find it using Object property. var count = Object . keys (arrObj). length ; console . log ('Object length is: ', count ); >>> Output Object length is: 3 So inshort by using Object.keys()  Javascript Object function you can find the size of object easily. The Object.keys()  method returns an array of a given object's own property  names in the same order a...

Installing Ganache CLI & Installing Ganache GUI

Image
source:https://raw.githubusercontent.com/trufflesuite/ganache-cli/develop/resources/icons/ganache-cli-128x128.png  What is Ganache? Ganache is part of truffle suit of Ethereum developers tools for you personal blockchain for Ethereum development. Ganache allows you to run your own blockchain on your local machine so you can test your contracts or DApp on your local machine instead of using testnet or mainnet. Ganache comes with two components to make it user-friendly. Ganache CLI Ganache GUI What is Ganache CLI? Ganache CLI allows you to create your own local blockchain environment using terminal commands. You can use terminal or CMD to run your ganache CLI. Ganache CLI also included in Truffle so do not need to install it separately.  Installing Ganache CLI ganache-cli is written in JavaScript and distributed as a Node.js package via npm. Using npm: npm install -g ganache-cli or you can use yarn  yarn global add...

Mastering in Javascript | Conditionals

Image
Mastering in Javascript: As a JavaScript developer, we have to handle multiple conditions to match our requirements. So here are some better ways to handle conditionals. Using Array.every for conditioning object array elements: This will is a common condition to check the object array contains the same value for value or not for a key, so lets take an example as follows: const jar = [ { name: 'orange', color: 'orange' }, { name: 'apple', color: 'red' }, { name: 'guava', color: 'green' } ]; function check() { let isAllRed = true; // condition: all fruits must be red for (let f of jar) { if (!isAllRed) break; isAllRed = (f.color == 'red'); } console.log(isAllRed); // false } check(); If you see the code we have to check whether each array element color is red or not. So we did the loop on each element and added the flag to check whether its true or not, but the code is...

Mastering in Javascript | Find Value in an array Object

Image
Mastering in Javascript: As the title suggests I am going to write one new series for mastering in javascript , here I will write some useful tips and tricks which will help you to write better code. Find value in an array of object Let's take an example as follows: let arrObj = [ { id :201,name: "Vikas" , age : 27 }, { id :204, name: "Rahul" , age : 25 } ]; Now you have arrObj and you want to check whether Rahul name is present or not and return that object from an array. Now we will see it with looping to find the value. function search ( name , myArray ){ for ( var i = 0 ; i < myArray . length ; i ++) { if ( myArray [ i ]. name === name) {                return myArray [ i ]; } } } var resultObject = search("Rahul", array); The output will be as follows: Now if we use ES6 then our code will be only one line which as follow...

Mastering in JavaScript | Sort multidimensional Array

Image
If you are a Javascript developer then you surely come to a place where you have to sort JSON object or another word sort javascript array of object by key. So today I will show you how can you sort your JSON object with alphabetic order. Let's take an example of the following array. var arrObject = [ { "id": 0, "userName": "Vikas Kad", "age":26 }, { "id": 1, "userName": "Akshay Shelke", "age":29 }, { "id": 2, "userName": "Rahul Konde", "age":22 } ]; Now here is the output if we log this array object. So let's create a function to sort the array object. function sortJSONArray(value1,value2) { return ((value1.userName == value2.userName) ? 0 : ((value1.userName > value2.userName) ? 1 : -1 )); } arrObject.sort(sortJSONArray); Now use our arrObject to sort it out. So output will be like this. now ...