Tuesday, November 27, 2018

JavaScript Array sort by several parameters

Array.prototype allows us to sort array just by 1 parameter. I have created my own method 'sortBy' to fix this gap. The method also allows to sort by desc. Let's say we have the following array
  
var objects = [{'Name': 'John', 'Age': 23, 'Profession': 'Accountant'},
    {'Name': 'Adam', 'Age': 18, 'Profession': 'Engineer'},
    {'Name': 'Vik', 'Age': 46, 'Profession': 'Architect'},
    {'Name': 'Jane', 'Age': 36, 'Profession': 'Developer'},
    {'Name': 'Rikky', 'Age': 28, 'Profession': 'Developer'}];
The following function call sorts the array by 'Profession' then by 'Name' descendantly
  
sortBy(objects, 'Profession', {'Name': 'desc'});
console.table(objects);
The result will be the following:

Now let's have a look at the method implementation.

Wednesday, November 14, 2018

Sorting C3 chart tooltip

C3 is very simple free JavaScript library that allows to create various types of chart literally in few lines of code. C3 is based on D3 so we must plugin it as well

  
  
  
  

  <div id="chart"></div>
  

That small code snippet produces such a beautiful chart with a tooltip:




But as you can see, the data in the tooltip are not sorted. The goal of this post is to show how to sort it. 

Thursday, November 8, 2018

Adding legend to D3 chart

D3 is very powerful free JavaScript library that allows to do many things such as DOM manipulations, working with data and shapes, smoth transitions between UI states etc. I show just a simple example how I adedd a legend into a coloured barchart.


Friday, November 2, 2018

PowerShell Get, Filter, Where, Copy in a single line

The task is the following: create a simple script for gathering textual log files from several different places via network, filter them by name and recent update date, display files information like name, datetime, length and copy them to a specified destination. It is pretty achievable through the PowerShell functionality.