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
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.List; | |
enum Color { | |
RED, GREEN; | |
} | |
interface Vegetable { |
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
import java.util.ArrayList; | |
import java.util.Collection; | |
import java.util.List; | |
import java.util.stream.Collectors; | |
enum Color { | |
RED, GREEN; | |
} | |
class Apple { |
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
import scala.annotation.tailrec | |
def sum(numbers: Seq[Int]): Int = | |
if (numbers.isEmpty) 0 | |
else numbers.head + sum(numbers.tail) | |
def product(numbers: Seq[Int]): Int = | |
if (numbers.isEmpty) 1 | |
else numbers.head * product(numbers.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
public class Factorial { | |
public int fact(int number) { | |
int i = 1; | |
int result = 1; | |
while (i <= number) { | |
result = result * i; | |
i++; | |
} | |
return result; | |
} |
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
// step 1 | |
object Factorial { | |
def fact(n: Int) = | |
if (n == 2) 2 | |
else if (n == 5) 120 | |
else 1 | |
} | |
// step 2 | |
object Factorial { |
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
class A { | |
static { | |
System.out.println("static A"); | |
} | |
static { | |
System.out.println("static A2"); | |
} |
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
import java.util.*; | |
List<String> list = new ArrayList<>(); | |
list.add("one"); | |
list.add("two"); | |
for( String str : list) { | |
System.out.println(str); | |
list.add("three") | |
} |
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
import scala.annotation.tailrec | |
def sum(numbers: Seq[Int]): Int = | |
loopRight(numbers, 0, _ + _) | |
def product(numbers: Seq[Int]): Int = | |
loopRight(numbers, 1, _ * _) | |
def sumTail(numbers: Seq[Int]): Int = | |
loopLeft(numbers, 0, (acc, i) => acc + 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
// sort data in column using string representation on numeric values | |
// natural order: 1, 3, 2, 0 | |
$(function () { | |
$.fn.dataTable.ext.order['my-sort'] = function (settings, col) { | |
return this.api().column(col, {order: 'index'}).nodes().map(function (td, i) { | |
var text; | |
switch ($(td).text()) { | |
case "0": | |
text = "zero"; |
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
integration :: (Double -> Double ) -> Double -> Double -> Double | |
integration f a b = let | |
step = (b-a)/1000 | |
helper acc 0 x = acc | |
helper acc cnt x = | |
helper (acc + ((f x) + (f next))/2 * step) (cnt - 1) next | |
where next = x + step | |
in helper 0 1000 a |
OlderNewer