↑ All Courses

String Interpolation

C♯

$”{name} is {age:f1} years old”;

Regular Expressions

Ruby

x =~ /text/
has_separator = /[ -]/.match?(value)

Collection Range

Ruby

c[0..2]

Loop over a range of values

Java

range(0, 10).forEach(n -> {});

Ruby

(40..90).each do |note|

Iterate

JavaScript

for (let val of it)

corners.forEach((coords, i) => {…})

C♯

foreach (var item in items)

Create an array of things

JavaScript

Array.from({length: 5}, (v, i) => i);

Checkbox Checked

jQuery

$(…).is(':checked')

Format to some number of decimal places

Python

f'{1.234:.1f}'

Java

System.out.printf("i: %d, sum: %d\n", i, sum);

Remove from end of array

JavaScript

a.pop()

Add to front of array

JavaScript

a.unshift(elem)

Add to end of array

JavaScript

push

Test a predicate against every element

JavaScript

[1,2,3].every(n => n === n))

Extract array from p5 vector

v.array()

p5.js

3D z

Increases coming towards you.

Change case

Ruby

'ABC'.downcase()

Python

'ABC'.lower()

Java

"ABC".toLowerCase()

Strip chars from string

Ruby

puts 'a.b'.tr('.', '')

Array element exists

Ruby

matches.any? {|u| u.email == email}

Scope

Ruby

Top, module, class, method (no special scope inside blocks like ifs)

Sets

Ruby

=== or include?

Python

s = set()
s.add(e)
in

XmlHttpRequest

CoffeeScript

MDN

fetch('/polled_events/searches')
.then((response) -> response.json())
.then((data) ->
  console.log(data)
).catch((error) -> console.error(error))

Queues

Python

from queue import Queue
q = Queue()
q.put(e)
q.get()
q.empty()

Format real numbers

Python

f-strings

f'result: {value:{width}.{precision}}'
print(f'Pi, rounded: {math.pi:.4}')
Pi, rounded: 3.142

Java

System.out.printf("Pi, rounded: %.3f", PI);
Pi, rounded: 3.142