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
| type tree = Leaf | Node(int, tree, tree); | |
| let rec sum = (item) => { | |
| switch (item) { | |
| | Leaf => 0 | |
| | Node(value, left, right) => value + sum(left) + sum(right); | |
| } | |
| }; | |
| let rec height = (root) => { |
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 iframeURLChange(iframe, callback) { | |
| var lastDispatched = null; | |
| var dispatchChange = function () { | |
| var newHref = iframe.contentWindow.location.href; | |
| if (newHref !== lastDispatched) { | |
| callback(newHref); | |
| lastDispatched = newHref; | |
| } |
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
| import React from 'react'; | |
| import logo from './logo.svg'; | |
| import './App.css'; | |
| // Add these two imports | |
| import Elm from 'react-elm-components'; | |
| import Main from "./Main"; | |
| function App() { | |
| return ( |
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
| -- Extracted from: https://guide.elm-lang.org | |
| -- Read more about this program in the official Elm guide: | |
| -- https://guide.elm-lang.org/architecture/buttons.html | |
| module Main exposing (main) | |
| import Browser | |
| import Html exposing (Html, button, div, text) | |
| import Html.Events exposing (onClick) |
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
| // https://stackoverflow.com/a/30638226 | |
| // When printing an “Element” Chrome developer tools will request the 'id' property | |
| // If the 'id' property is fetched, then the devtools is open | |
| let checkStatus; | |
| let customElement = document.createElement('p'); | |
| document.body.appendChild(customToString); | |
| let element = new Image(); | |
| Object.defineProperty(element, 'id', { |
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
| componentDidUpdate(prevProps, prevState) { | |
| Object.entries(this.props).forEach(([key, val]) => | |
| prevProps[key] !== val && console.log(`Prop '${key}' changed`) | |
| ); | |
| Object.entries(this.state).forEach(([key, val]) => | |
| prevState[key] !== val && console.log(`State '${key}' changed`) | |
| ); | |
| } |
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
| (defn compute-collatz [num steps] | |
| (cond | |
| (= num 1) steps | |
| (even? num) (compute-collatz (/ num 2) (inc steps)) | |
| (odd? num) (compute-collatz (+ 1 (* num 3)) (inc steps)))) | |
| (defn collatz [num] | |
| {:pre [(pos? num)]} | |
| (compute-collatz num 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
| (defn compute-collatz [num steps] | |
| (cond | |
| (= num 1) steps | |
| (even? num) (compute-collatz (/ num 2) (inc steps)) | |
| (odd? num) (compute-collatz (+ 1 (* num 3)) (inc steps)))) | |
| (defn collatz [num] | |
| ; Check if the provided number is positive. If not throw an error | |
| (if |
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
| import React from 'react'; | |
| import EventComponent from './EventComponent'; | |
| import { mount } from 'enzyme'; | |
| import { | |
| createStartTouchEventObject, | |
| createMoveTouchEventObject | |
| } from './EventHelpers.js'; | |
| describe('EventComponent', () => { |
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
| module Main exposing (main) | |
| import Browser | |
| import Html exposing (Html, button, div, text) | |
| import Html.Events exposing (onClick) | |
| type alias Model = | |
| { count : Int } |