Skip to content

Instantly share code, notes, and snippets.

cd /Users/rachel/dev
@RachelSa
RachelSa / Local_fresh.rb
Created September 19, 2016 02:28
My first command-line app, which suggests fresh foods based on user's location and the current month.
#A command-line app that suggests fresh foods
#based on user's location and the current month.
#The app automatically retrieves date and asks
#user for their region in the continental US.
#Ideas for expansion and improvements:
#allow user to choose alternate date,
#sort results by fruit and veg
@RachelSa
RachelSa / add
Created July 7, 2016 23:11
adds elements in array
function add(arr){
sum = 0
arr.forEach(function(num){
sum += num;
}); console.log(sum);
}
add([1,2,3,4,5])
add([-1,0,2])
add([3,3,3])
@RachelSa
RachelSa / removeLargest
Created July 7, 2016 22:57
removes n number of elements from an array, largest to smallest
//remove n number of elements from an array, largest to smallest
function removeLargest(arr,n){
for (var i = 0; i < n; i ++){
var sorted = Math.max.apply(null, arr);
//run through array, funding largest
var rem = arr.splice(arr.indexOf(sorted),1);
//remove largest
} console.log(arr);
}