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 Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
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
// multiplies by adding using a while loop within a closure | |
var MulbyAdding = {(x:Int, y:Int) -> Int in var add = 0; var count = 0; while count < y { | |
add += x | |
count += 1 | |
}; return add | |
} | |
// A Power closure that uses MulbyAdding and a while loop | |
var PowerbyMul = {(x:Int, y:Int) -> Int in var Pow = x; var count = 0; while count < y { | |
Pow *= x; count += 1 | |
}; return Pow |
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
not_reviewed_by_user = {restaurant_name(food_place):predictor(food_place) for food_place in restaurants if food_place not in reviewed} | |
for r in reviewed: #this for loop adds the restaurants reviewed by the user with the rating | |
not_reviewed_by_user.update({restaurant_name(r):user_rating(user, restaurant_name(r))}) | |
return not_reviewed_by_user |
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
// sums all the integers in an array | |
var ArraySum = {(var list:Array<Int>) -> Int in | |
var sum = 0 | |
for element in list { | |
sum += element | |
} | |
return sum | |
} | |
// uses a for loop to count the integers in an array | |
var ArrayCount = {(var list:Array<Int>) -> Int in |
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
// creates an array of integers from 0 to number-1 values | |
var RangeArray = {(number:Int) ->Array<Int> in var value = 0; var list = [Int]() | |
while value < number { | |
list.append(value) | |
value += 1 | |
} | |
return list | |
} | |
// creates an array of integers from num1 to num2-1 values | |
var SpecificRange = {(num1:Int, num2:Int) ->Array<Int> in var value = num1; var list = [Int]() |
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
//returns an array of integers that are divisible by num, within a parameter array | |
var DivisibleFilter = {(num:Int, divisor:Int) ->Bool in num % divisor == 0} | |
var DivisibleInRange = {(num:Int, list:Array<Int>) ->Array<Int> in var divlist = [Int]() | |
for element in list { | |
if DivisibleFilter(element, num) == true { | |
divlist.append(element) | |
} | |
} | |
return divlist |
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
// returns a dictionary that holds the indexes for every character in a string | |
func StringIndexer(str:String) ->Dictionary<Int, Character> { | |
var strlist = Array(str); var strdict = [Int:Character](); var indexer = 0 | |
for letter in strlist { | |
strdict.updateValue(letter, forKey: indexer) | |
indexer += 1 | |
} | |
return strdict | |
} | |
// returns an array containing the indexes where a character appears in a string |
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
// Returns a slice of an array that contains characters | |
func StringSlicer(list:Array<Character>, n1:Int, n2:Int) ->Array<Character> { | |
var slicer = n1; var slicedlist = [Character]() | |
while slicer <= n2 { | |
slicedlist.append(list[slicer]) | |
slicer += 1 | |
} | |
return slicedlist | |
} | |
// returns a slice of an array of characters with an increment |
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
// returns a dictionary that holds the indexes for every character in a string | |
func StringIndexer(str:String) ->Dictionary<Int, Character> { | |
var strlist = Array(str); var strdict = [Int:Character](); var indexer = 0 | |
for letter in strlist { | |
strdict.updateValue(letter, forKey: indexer) | |
indexer += 1 | |
} | |
return strdict | |
} | |
// returns an array containing the indexes where a character appears in a string |
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
//counts a specific letter in a string | |
func SpecificLetterCount(str:String, char:Character) ->Int { | |
var letters = Array(str); var count = 0 | |
for letter in letters { | |
if letter == char { | |
count += 1 | |
} | |
} | |
return count | |
} |
OlderNewer