Refactor
:my
=>
'code'
Codes
Refactorings
Popular
Best
Submit
Spam
Account
Logout
Login
JavaScript doesn't seem to be activated, expect things to be ugly and sloppy!
Learn How to Create Your Own Programming Language
createyourproglang.com
Recent
Simple Particle Engine for a shooter game
Snake / Nibbles clone in C and Ncurses
Please improve
Parsing of XML data has high CPU usage
Convert simple Javascript to jQuery plugin
Active Record getting unique records
List the files in a directory without the directory name or the extension
clean the code
ohs system, recruitment software, hr software, oh&s software, human resources software, ohs software
Array parsing in a block
Popular
Parsing of XML data has high CPU usage
Please improve
Snake / Nibbles clone in C and Ncurses
List the files in a directory without the directory name or the extension
Convert simple Javascript to jQuery plugin
Simple Particle Engine for a shooter game
Active Record getting unique records
Breadth first cartesian product iterator
php refactoring
first BST
Pastable version of
Ruby: array intersperse, efficiency
<pre class='prettyprint' language='ruby'>class Array # insert i between each element in the array # this is O( 2n ) ( I think! Is it? ) as the length of the list is not needed, but we need to initially make a copy of the list def intersperse( v ) tail = [ ].replace self # we need a shallow copy first_elem = tail.first second_elem = tail[ 1 ] arr = [ ] while first_elem arr.push first_elem if second_elem arr.push v tail = tail.drop 1 first_elem = tail.first second_elem = tail[ 1 ] else break end end arr end # this is faster, but I worry that for large arrays, storing i in memory will makes this slower # Bearing that in mind, since the speed at which this goes is determined by the length of the list as well as the length of the list stored in memory ( i ) is O( n^2 ) ( again, please correct me ) def intersperse( v ) arr = [ ] i = 0 j = 0 inc_jay = lambda { j = j + 1 } while i < length arr[ j ] = self[ i ] inc_jay.call if self[ i + 1 ] arr[ j ] = v inc_jay.call end i = i + 1 end arr end end</pre> <a href="http://www.refactormycode.com/codes/907-can-this-code-be-made-more-efficient" style="color:#fff" title="As seen on RefactorMyCode.com"><img alt="Small_logo" src="http://www.refactormycode.com/images/small_logo.gif" style="border:0" /></a>