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
object StringFinder { | |
/** | |
* Finds the first occurrence of a substring (`query`) within a `text`. | |
* @param text - the text to search in. | |
* @param query - the substring to find in `text`. | |
* @param pos - position in text to start searching from. | |
*/ | |
def find(text: String, query: String)(pos: Int): Unit = { | |
/* | |
* make sure `pos` hasn't gone out |
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
using System.Collections; | |
using System.IO; | |
class FileListings { | |
public void ListFiles() { | |
var directory = new System.IO.DriveInfo(@"C:\").RootDirectory; | |
var folders = new Stack<DirectoryInfo>(); | |
var files = new Stack<FileInfo>(); |
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 inRankingOrder(arr) { | |
return arr.sort((obj1, obj2) => { | |
const ranking1 = obj1.ranking, | |
ranking2 = obj2.ranking; | |
return ranking1 < ranking2 ? -1 : (ranking1 > ranking2 ? 1 : 0); | |
}); | |
} | |
function averageRanking(arr) { | |
const sum = arr.map(obj => obj.ranking). |
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.Scanner; | |
public class Depreciation { | |
private static Scanner scanner = new Scanner(System.in); | |
private static Column[] columns = { | |
new Column("Year", " "), | |
new Column("Start Value", " "), | |
new Column("Amt. Depreciated", " "), | |
new Column("Total Depreciation", "") | |
}; |
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
object Main { | |
type T = Any | |
trait Listy[T] { | |
val value: T | |
def isEmpty: Boolean | |
def head: Option[T] | |
def tail: Listy[T] | |
def filter(predicate: T => Boolean): Listy[T] = { | |
if (predicate(value)) ListyImpl(value, tail.filter(predicate)) else 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
/* | |
* Replace the contents of the "string" variable with the actual input numbers you have. | |
* Make sure you space them, with each number on its own line. | |
*/ | |
const numbers = ` | |
2 | |
1 | |
2 | |
3 | |
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
object ReverseSentence extends App { | |
if (args == null || args.length == 0) { | |
printf("%d arguments found; 2 arguments required.", Option(args).map(_.length).getOrElse(0)) | |
sys.exit(0); | |
} | |
if (args(0) == args(1)) { | |
println("The string parameters are equal.") | |
sys.exit(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
function createNode(key) { | |
const children = []; | |
const attributes = {}; | |
return { | |
key, | |
children, | |
attributes, | |
addChild(key) { | |
const child = createNode(key); |
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
object QuickSort { | |
def sort(list: Seq[Int]): Seq[Int] = { | |
if (list.length < 2) list | |
else { | |
val midIndex = list.length / 2 | |
val mid = list(midIndex) | |
val result = list.zipWithIndex.filter(_._2 != midIndex) | |
.partition(n => n._1 < mid) | |
result match { |
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
// flames.js | |
// FLAMES game. Algorithm can be found here: http://flamesgame.appspot.com/algorithm | |
const getFlame = (name1, name2) => | |
name1.toLowerCase().split(''). // take all characters in "name1", to compare | |
filter(c => name2.toLowerCase().includes(c)). // keep only characters (in "name1") also found in "name2" | |
reduce((result, c) => [ | |
result[0].replace(new RegExp(`${c}`, 'g'), ''), // replace common characters in "name1" | |
result[1].replace(new RegExp(`${c}`, 'g'), '') // replace common characters in "name2" | |
], [name1.toLowerCase(), name2.toLowerCase()]). |
OlderNewer