Skip to content

Instantly share code, notes, and snippets.

@jmsevold
jmsevold / array-removal.js
Created January 21, 2016 19:41
Remove an item from an array without mutating array
var list = ['a', 'b', 'c','d'];
var removeFromArray = (list,index) => {
var before = list.slice(0, index);
var after = list.slice(index + 1, list.length);
var result = before.concat(after);
return result;
};
@jmsevold
jmsevold / gist:2f6090fdc00c6f9e6d61
Created January 20, 2016 20:07
currying-and-composition
var compose = (func1,func2) => {
return (arg) =>{
return func1(func2(arg));
};
};
var upCase = (str) => str.toUpperCase();
var exclaim = (str) => `${str}!!!`;
var R = require('ramda');
var list = [1,2,3,4,5];
var filter = R.curry(function(func,array){
return array.filter(func);
})
var oddsOnly = function(num){
@jmsevold
jmsevold / promise-example.js
Last active April 14, 2016 22:18
Promise example
var p = new Promise(function(resolve, reject) {
if(1 === 1) { // set 1===2 to make it fail
resolve('Success!');
}
else {
reject('Failure!');
}
});
var fetch = require('node-fetch');
// fetch('https://api.github.com/users/jmsevold')
// .then(function(res) {
// return res.json();
// }).then(function(result) {
// url = result.followers_url
// }).catch(function (error) {
// console.log(error);
// });