Friday, April 20, 2018

JavaScript set object key by variable

ES6

var key = "name";
var person = {[key]:"John"};
console.log(person); // should print  Object { name="John"}

Before ES6

var person = {};
var key = "name";

person[key] /* this is same as person.name */ = "John";

console.log(person); // should print  Object { name="John"}

Thursday, April 19, 2018

Give random colors to text in a page using D3

d3.selectAll("*").style("color", function() {
  return "hsl(" + Math.random() * 360 + ",100%,50%)";
});

Get Indian financial year based on date

This function lets you get the start and end date of Indian financial year based on given date. This can also be modified for US financia...