Given an input.txt
that represents a linked list a -> b -> c -> d -> e
as a series of nodes with next
pointers:
a>b
b>c
c>d
d>e
Reverse the linked list such that the output reads:
object Foo { | |
var initialized = 0 | |
// This only happens once regardless of how many times Foo.fetch() is called | |
initialized = initialized + 1 | |
def fetch(): Integer = initialized | |
} | |
class Foo { |
while (current != null) { | |
next = current->next; | |
current->next = prev; | |
prev = current; | |
current = next; | |
} | |
head = prev; |
Given an input.txt
that represents a linked list a -> b -> c -> d -> e
as a series of nodes with next
pointers:
a>b
b>c
c>d
d>e
Reverse the linked list such that the output reads:
#!/usr/bin/env bash | |
# Where input.txt is: | |
# a>b | |
# b>c | |
# c>d | |
# d>e | |
paste -d '>' <(< input.txt | cut -d'>' -f2 | tac) <(< input.txt | cut -d'>' -f1 | tac) |
#!/usr/bin/env bash | |
seq 1 100 | \ | |
xargs -Ix -n1 echo "x + ((x % 3 == 0) + ((x % 5) == 0) * 2) * 1000" | \ | |
bc | \ | |
xargs -n1 printf "%04d\n" | \ | |
sed 's/^1.*/Fizz/' | \ | |
sed 's/^2.*/Buzz/' | \ | |
sed 's/^3.*/FizzBuzz/' | \ | |
sed 's/^0*//' |
// There is no String.substr on Salesforce. This uses String.substring instead. | |
// substring's arguments are different, so this just converts substr args to | |
// their substring equivalents. | |
function substrShim (str, start, len) { | |
if (len <= 0) | |
return ''; | |
if (start < 0) | |
start = str.length + start; |
define('foo', function () { | |
function Foo () { | |
Write('Hello World'); | |
}; | |
return Foo; | |
}) | |
require(['foo'], function (Foo) { | |
// Foo is undefined on Salesforce |
Platform.Load('Core', '1.0'); | |
function moo (foo, bar) {}; | |
Write(moo.length); // You'll get a .NET error if you do this, weirdly enough. |
function newEnv () { | |
function Foo () { | |
Write('Hello World'); | |
}; | |
var f = { | |
Foo: Foo | |
} | |
return f; |
function foo() { | |
function boom() { | |
Write('Boom'); | |
}; | |
function bar () { | |
function baz() { | |
boom(); // Fails here, "boom" can't be found | |
}; |