What is the difference between forEach
and map
in JS?
forEach:
const arr = [1, 2, 3];
const eachExample = () => arr.forEach(e => e);
const express = require('express') | |
const cors = require('cors') | |
const bodyParser = require('body-parser') | |
const app = express() | |
app.use(bodyParser.urlencoded({ extended: true })) | |
app.use(cors()) | |
app.post('/dev_log', function (req, res, next) { |
fn cluster(trimmed: i64) { | |
let range: Vec<i64> = (0..trimmed + 1).collect(); | |
range.par_iter() | |
.map(|i| thread::spawn(move || run(i.to_le()))) | |
.map(|runner| runner.join()); | |
} |
macro_rules! actions({ | |
$( $action: expr => $function: expr ), + } => {{ | |
let mut store = ::std::collections::HashMap::new(); | |
$(store.insert($action as &str, $function as Box<Fn(&str)>);) + store | |
}}; | |
); | |
fn main() { | |
let actions = actions!{ | |
"foo" => Box::new(|arg: &str| println!("foo {}", arg)), |
class EmailField extends Component { | |
constructor() { | |
super(); | |
this.state = { | |
email: '', | |
}; | |
} | |
handleClick = (e) => { | |
this.props.dispatch('SOMETHING', { email: e.target.innerText }): |
// here we import 'html' instead of just 'h' | |
import { html } from 'hyperapp'; | |
// now we use the 'html`` template tag literal | |
const view = (model, msg) => (html` | |
<div class="counter"> | |
<h1>Welcome to the hyperapp-one boilerplate!</h1> | |
<p><em>With JSX</em></p> | |
<hr class="line-break" /> | |
<section> |
class Node { | |
constructor(data = null, next_node = null) { | |
this.data = data; | |
this.next_node = next_node; | |
} | |
} | |
class List { | |
constructor() { | |
this.head = new Node(); |
class Rubux | |
attr_reader :state | |
def initialize(state = {}, actions = {}) | |
@state = state | |
@actions = actions | |
end | |
def dispatch(key, value) | |
return @state = @state.merge(@actions[key].(state, value)) if @actions[key] |
<!DOCTYPE html> | |
<html> | |
<head> | |
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css"> | |
</head> | |
<body> | |
<h1>My First Heading</h1> | |
<p>My first paragraph.</p> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> |