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
| myAudio = new Audio(audioUri + phrase + audioFormat); | |
| myAudio.play(); | |
| //anti-pattern: does not work | |
| return Rx.Observable.fromEvent(myAudio, 'onended'); | |
| myAudio.onended = () { | |
| return Rx.Observable.just("success"); | |
| } |
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 findPrimeFact(num, accum = []) { | |
| return 1; | |
| } | |
| function isDivisible(num) { | |
| return (divisor) => num % divisor === 0; | |
| } | |
| function isPrime(num) { | |
| return Array.from({length: Math.floor(num/4 - 1)}, | |
| (x, i) => i * 2 + 3) | |
| .filter(isDivisible(num)).length === 0; |
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 genSeqUntil(valFunc, limitPredicate, seq = []) { | |
| var nextVal = valFunc(seq.length); | |
| if (limitPredicate(seq.length, nextVal)) { | |
| seq[seq.length] = nextVal; | |
| return genSeqUntil(valFunc, limitPredicate, seq); | |
| } | |
| return seq; | |
| } | |
| const memoize = (fn) => (function () { | |
| var cache = {}; |
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 genSeqUntil(valFunc, limitPredicate, seq = []) { | |
| var nextVal = valFunc(seq.length); | |
| if (limitPredicate(seq.length, nextVal)) { | |
| seq[seq.length] = nextVal; | |
| return genSeqUntil(valFunc, limitPredicate, seq); | |
| } | |
| return seq; | |
| } | |
| function sumOfAllMultiplesUnder(multsArr, max) { |
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 assert = require('assert'); | |
| var xys = [{"x":[1,6],"y":7},{"x":[2,4],"y":8},{"x":[3,7],"y":16},{"x":[6,8],"y":44},{"x":[7,1],"y":50},{"x":[8,4],"y":68}]; | |
| var euSqDist = (pt1, pt2) => Math.pow(pt1[0] - pt2[0], 2) + Math.pow(pt1[1] - pt2[1], 2); | |
| var manDist = (pt1, pt2) => pt1[0] - pt2[0] + pt1[1] - pt2[1]; | |
| var genArr = function (len) { | |
| return Array.apply(null, Array(len)).map(function () { | |
| }); | |
| }; | |
| var pluck = (prop) => (el) => el[prop]; |
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
| var assert = require("assert"), | |
| _ = require("underscore"), | |
| testData = { | |
| "Iron Man": ["Robert Downey Jr", "Gwyneth Paltrow", "Terrence Howard"], | |
| "Iron Man 3": ["Robert Downey Jr", "Guy Pearce", "Gwyneth Paltrow"], | |
| "Super Troopers": ["Jay Chandrasekhar", "Kevin Heffernan"], | |
| "The Day After Tomorrow": ["Dennis Quaid", "Jake Gyllenhaal", "Emmy Rossum"], | |
| "The Phantom of the Opera": ["Gerard Butler", "Emmy Rossum", "Patrick Wilson"], | |
| "How I Met Your Mother": ['Josh Radnor', "Jason Segel", "Cobie Smulders", "Kevin Heffernan"], | |
| "Despicable Me": ['Steve Carell', 'Jason Segel', 'Russel Brand', "Michael Fassbender"], |
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 isPalindrome(str) { | |
| var middle = Math.floor(str.length / 2), | |
| m = 0, | |
| strArr = str.toLowerCase().split(""); | |
| for (m; m <= middle; m++) { | |
| if (strArr[m] !== strArr[strArr.length - 1 - m]) { | |
| 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
| var assert = require("assert"); | |
| function largestSubArray(arr) { | |
| var allArrayPoints = set(0, arr.length) | |
| .reduce(commissionArrayPoints(arr), []); | |
| return allArrayPoints.reduce(greaterComparator, allArrayPoints[0]); | |
| } | |
| function commissionArrayPoints(arr) { | |
| return function (accum, num) { |
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
| var assert = require('assert'); | |
| function sortMerged(lOne, lTwo) { | |
| return lOne.reduce(function (sortedList, num, index) { | |
| var position = findPositionBinary(sortedList, num); | |
| sortedList.splice(position, 0, num); | |
| return sortedList; | |
| }, lTwo); | |
| } |
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
| var nike = (function () { | |
| var eventChain = [], | |
| thisJqEle; | |
| return { | |
| findElement: function (elementSelector, asyncTimeout) { | |
| //async should be the lenght of time to wait when looking async for the ele | |
| //sync only now | |
| eventChain.push(function (elementSelector, asyncTimeout) { | |
| return function () { |