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 fakePromise(id) { | |
| var deferred = $.Deferred(); | |
| setTimeout(function() { | |
| console.log(id + ' is done'); | |
| deferred.resolve(id); | |
| }, Math.random() * (1000 - 500) + 500); | |
| return deferred.promise(); | |
| } | |
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
| module.exports = function checkBal(input) { | |
| function match(left, right) { | |
| return left === '(' && right === ')'; | |
| } | |
| function removeLast(ar) { | |
| return ar.slice(0, ar.length - 1); | |
| } | |
| var result = input.split('').reduce(function(prev, curr, index, array) { | |
| if (!prev.length) return [curr]; | |
| if (match(prev[prev.length -1], curr)) return removeLast(prev); |
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
| console.log( | |
| Array.apply(null, {length: 100}).map(function(val, index) { | |
| return (++index%3?'':'Fizz')+(index%5?'':'Buzz')||index; | |
| }).join('\n') | |
| ); | |
| console.log( | |
| Array.apply(null, {length: 100}).map(function(val, index) { | |
| index++; | |
| if (index % 15 == 0){return "FizzBuzz";} |
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
| // Init a source array contains numbers 0-35 | |
| var source = Array.apply(null, {length: 36}).map(Number.call, Number); | |
| // Init the result array as undefined using the arguments pseudo array. | |
| var result = Array.apply(null, {length: 100}); | |
| // The magic | |
| result = result.map(function(val, index) { | |
| return source[index % source.length]; | |
| }); |
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 checkSum(groupOfInputs, maxValue) { | |
| groupOfInputs = $(groupOfInputs); | |
| groupOfInputs.on('change keyup paste', function() { | |
| $this = $(this); | |
| var values = groupOfInputs.map(function() {return $(this).val();}).get(); | |
| var sum = values.reduce(function(one, two) { | |
| return Number(one) + Number(two); | |
| }); | |
| if (sum > maxValue) { | |
| alert('Too big!'); |
NewerOlder