This file contains hidden or 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 contains(c, s) { | |
var index = typeof s === 'string' ? s.indexOf(c) : -1; | |
return index > -1; | |
} | |
console.log(contains("hi", "there")); // false | |
console.log(contains("hi", "hi, all")); // true | |
console.log(contains("hi", 1)); // false | |
console.log(contains("hi", null)); // false |
This file contains hidden or 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 contains(c: string, arr: string) { | |
var index = arr.indexOf(c); | |
return index > -1; | |
} | |
console.clear(); | |
console.log(contains("hi", "there")); // false | |
console.log(contains("hi", "hi, all")); // true | |
console.log(contains("hi", 1)); // doesn't compile | |
console.log(contains("hi", null)); // TypeError: Cannot read property 'indexOf' of null |
This file contains hidden or 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 contains(c, s) { | |
var index = s.indexOf(c); | |
return index > -1; | |
} | |
console.log(contains("hi", "there")); // false | |
console.log(contains("hi", "hi, all")); // true | |
console.log(contains("hi", 1)); // TypeError: s.indexOf is not a function | |
console.log(contains("hi", null)); // TypeError: Cannot read property 'indexOf' of null |
This file contains hidden or 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
'use strict'; | |
var gulp = require('gulp'), | |
http = require('http'), | |
st = require('st'), | |
exec = require('child_process').exec, | |
gutil = require('gulp-util'), | |
clear = require('clear'), | |
counter = 0; |
This file contains hidden or 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
{- OVERVIEW ------------------------------------------------------ | |
A "Tree" represents a binary tree. A "Node" in a binary tree | |
always has two children. A tree can also be "Empty". Below I have | |
defined "Tree" and a number of useful functions. | |
This example also includes some challenge problems! | |
-----------------------------------------------------------------} |
This file contains hidden or 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
OperatorTable addAssignOperator(":", "atPutNumber") | |
curlyBrackets := method( | |
r := Map clone | |
call message arguments foreach(arg, | |
r doMessage(arg) | |
) | |
r | |
) |
This file contains hidden or 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
Matrix := Object clone | |
Matrix dim := method(x, y, | |
self matrix := list(); | |
for(1, 0, x - 1, 1, | |
row := list(); | |
for(1, 0, y - 1, row push(0)); | |
matrix push(row) | |
) | |
) |
This file contains hidden or 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
l = list(1,2,3,4,5) | |
l average := method( | |
s := self size; | |
if( | |
size==0, | |
0, | |
self reduce(+) / size | |
) | |
) | |
l average # => 3 |
This file contains hidden or 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
a := list(list(1,2,3), list(4,5,6), list(7,8,9)) | |
a flatten reduce(+) |
This file contains hidden or 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
old_div := Number getSlot("/") | |
Number / := method(den, if( den == 0, 0, self old_div(den))) | |
2/0 # => 0 | |
4/2 # => 2 |