####What's the greatest common divisor of two numbers?
'use strict';
let euclid = (int1, int2) {
if(int1 === int2)
return int1;
if(int1 > int2)
####What's the greatest common divisor of two numbers?
'use strict';
let euclid = (int1, int2) {
if(int1 === int2)
return int1;
if(int1 > int2)
const makeUpperCase = (word) => word.toUpperCase(); | |
const makePlural = (word) => word + 's'; | |
makePlural('shoe');//=> 'shoes' | |
makeUpperCase('shoe');//=> 'SHOE' | |
const compose = (x, y) => { | |
return function (z) { | |
return x(y(z)); |
$( document ).ready( function () { | |
$.getJSON("#dataobject", (data) => { | |
let imgArray = matchElements(data)(/(?:scontent)/); | |
//place and style the user avatar thumbnail | |
placeAvatar(".img-thumbnail", imgArray[0]); | |
//display the user's feed | |
$( ".img-display" ).html("<img src='" + imgArray[1] + "'/>"); |
/**Some of the image URLs in the datastore are broken. This ```matchElements``` function returns a new array of valid URLs that match the ``@param {Regex} match` object. | |
*/ | |
const matchElements = (arr) => | |
function (match) { | |
return arr.filter((str) => match.test(str)) | |
} |
var reset = document.getElementById('reset'); | |
reset.addEventListener('click', function(e) { | |
location.reload(); | |
}); |
var wt = require('webtorrent'); | |
var client = new wt(); | |
client.seed(__dirname + '/astro.jpg', function (torrent) { | |
console.log('seeding the file ', torrent.infoHash); | |
}); |
/** Once takes a function as an argument and returns a function or undefined, depending on whether the fn passed as an argument | |
* has been called. If that function hasn't been invoked, Once will return the value of that function applied to any arguments. | |
* otherwise it will return undefined. | |
*/ | |
// implementation #1 | |
function once (fn) { | |
var run = false | |
return function () { | |
if (run) return void 0 |
function delay (fn, wait) { | |
var args = Array.prototype.slice.call(arguments, 2) | |
setTimeout(function () { | |
return fn.apply(this, args) | |
}, wait) | |
} | |
// with ES6 rest operator instead of slicing arguments object | |
const delay2 = (fn, wait, ...args) => { | |
setTimeout(() => fn.apply(this, args), wait) |
/** Memoize takes a function as an argument and returns a function. When the supplied function is called, it is stored in a | |
* lookup table. That way the next time it's called the passed function won't run again and will instead return the stored value. | |
*/ | |
function memoize (fn) { | |
var cache {} | |
return function () { | |
var args = Array.prototype.slice.call(arguments) | |
var key = JSON.stringify(args) | |
if (key in cache) return cache[key] | |
else { |
/** | |
* input: @arr array | |
* @out array | |
* @cycles integer | |
* output: @out, array of @cycles repetions of @arr | |
* ex: cartwheel([1,2,3], 3) --> [1,2,3,1,2,3,1,2,3] | |
*/ | |
const cartwheel = (arr, out = [], cycles) => | |
cycles === 0 |