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
{ | |
"name": "caravan", | |
"version": "1.0.0", | |
"description": "travel awesome", | |
"main": "./lib/index.js", | |
"config": { | |
"sass_command": "./node_modules/node-sass/bin/node-sass" | |
}, | |
"scripts": { | |
"test": "npm run test", |
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
// destructuring and default values | |
const give_discount = ({item, price, percent_discount=10})=>{ | |
console.log('For the ' + item + ' listed at $' + price + | |
', you get ' + percent_discount + '% off!') | |
} | |
give_discount({item: 'sweater', price: 200, percent_discount: 25}) | |
//=> For the sweater listed at $200, you get 25% off! | |
give_discount({item: 'dress shoes', price: 350}) |
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
// elision AKA skipping array elements | |
let [b, , , , , a] = ['Robin!', 'Nana', 'nana', 'nana', 'nana', 'Batman!'] | |
console.log(a) //=> Batman! | |
console.log(b) //=> Robin! |
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
(def jokers-challenge ["Robin!" "Nana" "nana" "nana" "nana" "Batman!"]) | |
; elision AKA destructuring that skips vector items | |
(let [[b _ _ _ _ a] jokers-challenge] | |
(println a) | |
(println b)) | |
;=> Batman! | |
;=> Robin! |
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
// rest operator example | |
const print_the_rest = ([a, b, ...remaining_values]) => remaining_values.map(item => console.log(item)) | |
print_the_rest(["celebration", "can you feel it", "fantasy", "september", "boogie wonderland", "getaway"]) | |
//=> fantasy | |
//=> september | |
//=> boogie wonderland | |
//=> getaway |
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
; rest operator example | |
(defn print-the-rest | |
;prints the rest of the collection | |
[[a b & remaining-values]] | |
(doall (map println remaining-values))) | |
(print-the-rest ["celebration" "can you feel it" "fantasy" "september" "boogie wonderland" "getaway"]) | |
;=> fantasy | |
;=> september |
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
const request = require('request') | |
const isMovie = (item) => { | |
if (item.Type === "movie") return true | |
return false | |
} | |
const movies = request('http://omdbapi.com/?s=highlander', | |
((err, res, body) => { |
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
(ns clojure-noob.core | |
(:gen-class) | |
(:require [clojure.data.json :as json] | |
[clojure.pprint :as pp])) | |
(defn get-url | |
"get a url's content" | |
[url] | |
(-> url | |
slurp |
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 destructuring | |
const eat_pizza_picky_style = ({dough, sauce, meat}) => { | |
console.log('For this pizza, Whiskers only eats the ' | |
+ dough + ', ' + sauce + ', and ' + meat | |
+ '. It picks everything else off!') | |
} | |
const pepperoni_pizza = { | |
cheese: 'mozzarella', | |
dough: 'white flour dough', |
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 destructuring | |
(defn eat-pizza-picky-style | |
; for eating only the good stuff from a pizza | |
[{:keys [dough meat sauce]}] | |
(println (str | |
"For this pizza, Whiskers only eats the " | |
dough ", " meat ", and " sauce | |
". It picks everything else off!"))) | |
(def pepperoni-pizza { |