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 string = '__NAME__ came to our __EVENT__ and __ACTION__'; | |
| const opts = { | |
| name: 'Jared', | |
| event: 'movie', | |
| action: 'loved it' | |
| }; | |
| const stringReplacer = (string, opts) => { | |
| const newString = string |
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
| class Person | |
| attr_accessor :name | |
| def initialize(name) | |
| @name = name | |
| end | |
| end | |
| p = Person.new('L. Ron') | |
| puts p.name |
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 https = require('https'); | |
| var getHTML = function getHTML(options, callback) { | |
| https.get(options, function (response) { | |
| response.setEncoding('utf8'); | |
| var bufferedContent = ""; | |
| response.on('data', function (content) { | |
| bufferedContent += content; | |
| }); |
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 chalk = require("chalk"); | |
| const log = console.log; | |
| log( | |
| chalk.hex("#FA6670").bold(" FLOWERS") + " can have" + chalk.hex("#970343")(" many ") + "colors" + | |
| " just like rainbows!\n " + | |
| chalk.bold.red("U") + chalk.bold.keyword("orange")("N") + chalk.bold.yellow("I") + chalk.bold.green("C") + chalk.bold.blue("O") + | |
| chalk.bold.hex("#b310de")("R") + chalk.bold.hex("#541b9f")("N") + " lives on " + "rainbows " + | |
| chalk.bold.hex("#D4AF37")("~~~~~~~!") |
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 makeLoadedDie() { | |
| var list = [5, 4, 6, 1, 6, 4, 2, 3, 3, 5]; | |
| var i = -1; | |
| return function() { | |
| i = i + 1; | |
| if(i===list.length){ | |
| i = 0; | |
| return list[i]; | |
| } else { |
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 animals = ["quokka", "capybara", "hedgehog", "koala", "fluffybunny"]; | |
| //calculate length | |
| var length = animals.map(function(animal) { | |
| return animal.length; | |
| }); | |
| //make them loud with uppercase | |
| var loud = animals.map(function(animal) { | |
| return animal.toUpperCase(); |
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 array = [1, 2, 10, 9, 5]; | |
| var sortArray = array.sort(function(a, b) { | |
| return a - b; | |
| }); | |
| array.sort(function(a, b) { | |
| if (a < b) { | |
| return -1; | |
| } else if (a > b) { |
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 input = [ | |
| { x: 3, y: 4 }, | |
| { x: 12, y: 5 }, | |
| { x: 8, y: 15 } | |
| ]; | |
| var result = input.map(function(triangle) { | |
| // console.log(Math.pow(x)); | |
| return Math.sqrt((Math.pow(triangle.x, 2) + Math.pow(triangle.y, 2))) | |
| }); |
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 findWaldo = function(arr, found) { | |
| for (var i = 0; i < arr.length; i++) { | |
| if (arr[i] === "Waldo") { | |
| found(i); | |
| } | |
| } | |
| } | |
| function actionWhenFound(index) { | |
| console.log("Found Waldo at index " + index); |
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 countLetters(sentences) { | |
| var obj = {}; | |
| for (var i = 0; i < sentences.length; i++) { | |
| if (sentences[i] !== ' ') { | |
| if (obj[sentences[i]] === undefined) { | |
| obj[sentences[i]] = []; | |
| } | |
| obj[sentences[i]].push(i); | |
| } | |
| } |
NewerOlder