Mathematical Range Summing

Immediately after the last post about summing a range of numbers, a talented friend of mine, Gábor, offered an even shorter, cleverer solution:

What I especially like about it is that instead of relying on esoteric JavaScript functions to do the job, it’s done with reasoning and plain maths, which makes it clearer and easier to read too.

The Maths.abs() call is only needed because in the original problem, the arguments could be in either order; the logic is still the same though, you just need to make sure the range is positive. In short, it’s (a+b) × (a-b+1) ÷ 2.

Sum All Numbers in a Range

A solution to Free Code Camp’s “Sum All Numbers in a Range” JavaScript challenge, in a Functional Programming style.

A friend of mine hosts meetups for the Free Code Camp, which describes itself as:

We’re an open source community of people who learn to code and help nonprofits.

He organises casual meetings in coffee shops to allow participants to work on their assignments in a nice environment and help each other. If you’re looking to learn programming I recommend finding a Free Code Camp group in your area.

Today I visited such a meeting and one of the Code Campers was working on a solution for one of the JavaScript problems in the Intermediate Algorithm Scripting section. The task was to write a function that takes an array of 2 numbers as an argument and returns the sum of all the numbers between them, including the 2 numbers themselves. For example, an input of [3, 1] should result in 6, because 1 + 2 + 3 = 6. As a hint, it’s recommended you read the documentation for Math.min(), Math.max() and Array.prototype.reduce(). Continue reading

Lean Poker

I had a lot of fun attending a Lean Poker event last weekend!

Me at Lean Poker

Me at Lean Poker

It’s a type of event where programmers get together, form teams and spend the day writing code competitively, to see who can write the best automated online-poker player. We don’t play for money but for pride, and the main aim is to practise writing beautiful code and lean principles. That said, given the time constraint of a single day, the focus is usually on Deliver as fast as possible and by the end I’m flurrying around to keep errors out of the code. We try to get quick feedback during the day (more on that later) but I thought I’d do a write about the event to give people who haven’t attended one of these before an idea of what it’s like!

Continue reading

CSS for TODO Elements

I wrote a small CSS class .todo for cases when you want to mark HTML elements on a page that you still want to work on later. Add this class to elements that aren’t ready yet, to mark them so that you won’t forget about them and ship the site unfinished. See the Gist’s description on GitHub for more information on how to use it. Here’s the code:

/sinisterstuf/4682224
/* CSS for adding TODO notes on WIP pages */
div.todo { /* style the text in a bright box */
  color: red;
  font-size: large;
	background-color: yellow;
	text-align: center;
	border: 3px solid red;
	border-bottom: 1px solid red;
	margin-bottom: 0;
	padding: 1px;
}
div.todo:before { /* prepend the word TODO to the text */
	font-weight: bold;
	content: "↓ TODO: "
}
div.todo+* { /* style the following element in a bright box too */
	border: 3px solid red;
	border-top: 0;
	margin-top: 0;
}