This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // blog-post - http://www.delimited.io/blog/2013/12/8/chord-diagrams-in-d3 | |
| //******************************************************************* | |
| // CHORD MAPPER | |
| //******************************************************************* | |
| function chordMpr (data) { | |
| var mpr = {}, mmap = {}, n = 0, | |
| matrix = [], filter, accessor; | |
| mpr.setFilter = function (fun) { | |
| filter = fun; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // See blog post for full details http://www.delimited.io/blog/2013/12/1/hexbins-with-d3-and-leaflet-maps | |
| //********************************************************************************** | |
| //******** LEAFLET HEXBIN LAYER CLASS ********************************************* | |
| //********************************************************************************** | |
| L.HexbinLayer = L.Class.extend({ | |
| includes: L.Mixin.Events, | |
| initialize: function (rawData, options) { | |
| this.levels = {}; | |
| this.layout = d3.hexbin().radius(10); | |
| this.rscale = d3.scale.sqrt().range([0, 10]).clamp(true); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //Blog post with working examples: http://www.delimited.io/blog/2013/12/19/force-bubble-charts-in-d3 | |
| d3.csv('data/fuel.csv', function (error, data) { | |
| var width = 1000, height = 1000; | |
| var fill = d3.scale.ordinal().range(['#827d92','#827354','#523536','#72856a','#2a3285','#383435']) | |
| var svg = d3.select("#chart").append("svg") | |
| .attr("width", width) | |
| .attr("height", height); | |
| _.each(data, function (elem) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function sqrt(num, guess) { | |
| guess = guess || num / 3; | |
| if (Math.abs(num - guess * guess) < 5e-15) { | |
| return guess; | |
| } else { | |
| return sqrt(num, (num / guess + guess) / 2); | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function fizzBuzz(num) { | |
| for (let i = 1; i <= num; i++) { | |
| const fizz = i % 3 === 0 ? 'Fizz': ''; | |
| const buzz = i % 5 === 0 ? 'Buzz': ''; | |
| console.log(fizz || buzz ? fizz + buzz: i) | |
| } | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //DFS | |
| Tree.prototype.traverse = function (callback) { | |
| var stack=[this]; | |
| var n; | |
| while(stack.length>0) { | |
| n = stack.pop(); | |
| callback(n.value); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function isPrime(num) { | |
| for (var i = 2; i < Math.sqrt(num); i++) { | |
| if (num % i === 0) return false; | |
| } | |
| return true; | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const insertionSort = arr => { | |
| const len = arr.length; | |
| let i, j, temp; | |
| for (i = 1; i < len; i++) { | |
| j = i; | |
| temp = arr[i]; | |
| while (j > 0 && arr[j - 1] > temp) { | |
| arr[j] = arr[j - 1]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const swap = (arr, index1, index2) => { | |
| [arr[index1], arr[index2]] = [arr[index2], arr[index1]]; | |
| }; | |
| const bubbleSort = (arr) => { | |
| const len = arr.length; | |
| for (let i = 0; i < len; i++) { | |
| for (let j = 0, k = len - 1 - i; j < k; j++) { | |
| if (arr[j] > arr[j + 1]) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const merge = (arrL, arrR) => { | |
| const result = []; | |
| let cursorL = 0; | |
| let cursorR = 0; | |
| while (cursorL < arrL.length && cursorR < arrR.length) { | |
| if (arrL[cursorL] < arrR[cursorR]) { | |
| result.push(arrL[cursorL++]); |
OlderNewer