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 softmax(output) { | |
var maximum = output.reduce(function(p,c) { return p>c ? p : c; }); | |
var nominators = output.map(function(e) { return Math.exp(e - maximum); }); | |
var denominator = nominators.reduce(function (p, c) { return p + c; }); | |
var softmax = nominators.map(function(e) { return e / denominator; }); | |
var maxIndex = 0; | |
softmax.reduce(function(p,c,i){if(p<c) {maxIndex=i; return c;} else return p;}); | |
var result = []; | |
for (var i=0; i<output.length; i++) |
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
package com.mulesoft.bat; | |
/* | |
* | |
* Copyright 2013 Netflix, Inc. | |
* | |
* Licensed under the Apache License, Version 2.0 (the "License"); | |
* you may not use this file except in compliance with the License. | |
* You may obtain a copy of the License at | |
* | |
* http://www.apache.org/licenses/LICENSE-2.0 |
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
[1,2] map (item, index) -> (item * 10 + index) |
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
/** | |
* This function returns a stream. We first populate the stream with a head value, | |
* and a lazy tail. | |
* In this case, we tell the engine the tail is a function call. | |
* That function call will be not be executed UNTIL the value of that call is needed. | |
*/ | |
fun leibnizTerm(n: Number = 0): Array<Number> = | |
[4 / (n + 1) - 4 / (n + 3) ~ leibnizTerm(n + 4)] | |
// ^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^ | |
// head lazy tail |
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
fun stdDev(values: Array<Number>): Number = do { | |
var average = avg(values) | |
var squareDiffs = values map do { | |
var diff = $ - average | |
--- | |
diff * diff | |
} | |
--- | |
sqrt(avg(squareDiffs)) | |
} |
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
%dw 2.0 | |
output application/json | |
fun sma(list: Array<Number>, window: Number) = | |
0 to (sizeOf(list) - window) map ($ to $ + window - 1) map avg(list[$]) | |
--- | |
sma([90, 40, 45, 100, 101], 2) |
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
fun Y(f) = do { | |
var x = | |
((h) -> (arguments) -> using(g = f(h(h))) g(arguments)) | |
(((h) -> (arguments) -> using(g = f(h(h))) g(arguments))) | |
--- | |
f(x) | |
} | |
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
fun indexOf<T>(array: Array<T>, elem: T, carry: Number = 0): Number = | |
array match { | |
case [] -> -1 | |
case [head ~ tail] -> | |
if(head == elem) | |
carry | |
else | |
findIndex(tail, elem, carry + 1) | |
} |
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
%dw 2.0 | |
output application/json | |
// See the documentation for this functions | |
import decodeURI, decodeURIComponent, encodeURI, encodeURIComponent from dw::core::URL | |
// Step 1) Enter http://rebrand.ly/dwl-2-playground | |
// Step 2) Copy and paste this code in the transformation editor | |
// You now will see the results in the right pane | |
// Step 3) Implement the parse(str) function | |
// Once you make a test pass, that test will dissapear |
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
%dw 2.0 | |
output application/json | |
fun while<T>(a, b: (T) -> Boolean) = do { | |
var r = a() | |
fun innerWhile(x) = do { | |
var r = a(x) | |
--- | |
b(r) match { | |
case true -> [r ~ innerWhile(r)] |
OlderNewer