Skip to content

Instantly share code, notes, and snippets.

@daguar
Last active August 29, 2015 13:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save daguar/8965561 to your computer and use it in GitHub Desktop.
Save daguar/8965561 to your computer and use it in GitHub Desktop.
Comparing the very basics of Ruby, Python, and Javascript syntax with a simple example

Goal

Iterate over an array of numbers and print each value

Python

array = [1,2,3,4]

for number in array:
	print(number)

Ruby

array = [1,2,3,4]

array.each do |number|
	puts number
end

Javascript

var array = [1,2,3,4];

array.forEach(function(number) {
	console.log(number)
});
@calvinmetcalf
Copy link

Got JavaScript array.forEach is the better syntax, this one won't work well

@Mr0grog
Copy link

Mr0grog commented Feb 12, 2014

It's a little confusing that you did the same thing twice in the Python one.

@daguar
Copy link
Author

daguar commented Feb 13, 2014

@Mr0grog: realized I left the 2nd one in :P

@calvinmetcalf: updated! I'm mostly a plumber in JS, so that's why it's great to have other people take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment