This file contains 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
var pos = [0,20,40,60,80,100]; | |
var valor = 15; | |
var resultado = pos.map(function (val){ return {val:val, dif: Math.abs(val-valor)};}).reduce(function(acc, pair){return (acc && acc.dif < pair.dif) ? acc : pair}).val; |
This file contains 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 warrior(speed, strength){ | |
console.log( | |
"Warrior: " + this.kind + | |
", weapon: " + this.weapon + | |
", speed: " + speed + | |
", strength: " + strength | |
); | |
} | |
var warrior1 = { |
This file contains 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
R.without = function (){ | |
var args = Array.prototype.slice.call(arguments); | |
var originalArray = args.pop(); | |
return R.reject(function (el){ return args.indexOf(el) != -1}, originalArray); | |
} |
This file contains 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
// Returns first element that matches CSS selector {expr}. | |
// Querying can optionally be restricted to {container}’s descendants | |
function $(expr, container) { | |
return typeof expr === "string"? (container || document).querySelector(expr) : expr || null; | |
} | |
// Returns all elements that match CSS selector {expr} as an array. | |
// Querying can optionally be restricted to {container}’s descendants | |
function $$(expr, container) { | |
return [].slice.call((container || document).querySelectorAll(expr)); |
This file contains 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
// http://stackoverflow.com/questions/15666048/service-vs-provider-vs-factory | |
var myApp = angular.module('myApp', []); | |
//Service style, probably the simplest one | |
myApp.service('helloWorldFromService', function() { | |
this.sayHello = function() { | |
return "Hello, World!" | |
}; | |
}); |
This file contains 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
// http://stackoverflow.com/questions/6094117/javascript-concat-to-string-at-beginning | |
mystr = mystr.replace (/^/,'John '); |
This file contains 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
http://stackoverflow.com/questions/25759046/iphone-6-and-6-plus-media-queries | |
/* 6 */ | |
@media only screen and (max-device-width: 667px) | |
and (-webkit-device-pixel-ratio: 2) {} | |
/* 6+ */ | |
@media screen and (min-device-width : 414px) | |
and (-webkit-device-pixel-ratio: 3) {} |
This file contains 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
// http://stackoverflow.com/questions/17626604/how-to-trigger-ng-change-in-directive-test-in-angularjs | |
changeInputValueTo = function(value) { | |
inputElm.val(value); | |
browserTrigger(inputElm, $sniffer.hasEvent('input') ? 'input' : 'change'); | |
}; |
This file contains 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
// http://grosser.it/2012/03/23/freeze-stub-time-in-jasmine-tests/ | |
withTimeFrozenAt("2012-01-01", function(){ | |
it("is frozen", function(){ | |
// do something useful with time | |
}) | |
}) | |
var withTimeFrozenAt = function(time, fn){ | |
describe('with time frozen at ' + time, function() { |
This file contains 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
console.log('jasmine-version:' + jasmine.getEnv().versionString()); |
NewerOlder