Skip to content

Instantly share code, notes, and snippets.

View rayshan's full-sized avatar
🕵️‍♀️
Inspecting stocks...

Ray Shan rayshan

🕵️‍♀️
Inspecting stocks...
View GitHub Profile
@rayshan
rayshan / angularjs.filter.coffee
Created January 11, 2014 19:29
JavaScript Math.round has issues with floats. This gives correct result. Inspiration: http://stackoverflow.com/questions/20701029/rounding-issue-in-math-round-tofixed
angular.module('app').filter 'round', () ->
(input, decimals) ->
return Math.round(input * Math.pow(10, decimals)) / Math.pow(10, decimals)
@rayshan
rayshan / gist:5578634
Created May 14, 2013 19:14
Javascript function to loop through flattened array and return whole object or value to specified key
/**
* loop through flattened array and return whole object or value to specified key
* e.g. array: [{"idKey": 1, "otherKey": "hello"},
* {"idKey": 2, "otherKey": "world"}]
* @param arr
* @param key search for this key
* @param value match searched key's value to desired value
* @param {string=} keyToReturn return value of this key
* @returns {*}
*/