StaffCoder
PHP
PHPPHP 8
10 modules · 49 challengesSign up
Module 2 of 10 · 5 challenges

PHP Functions and Closures

Learn how to call functions with default and named arguments, capture state in closures by value and by reference, write short arrow functions, pass functions around as callables, and compose them into a discount rule engine.
Finish every challenge, or complete the star challenge, to complete the module.

Challenges

5 challenges

Flexible Discount Calls

Sign up to unlock
—No data yeteasy
About this challenge

Give the discount helper default and named parameters so callers can skip and reorder settings safely.

Solved in a browser IDE and graded by tests. Sign up to solve

Price Caps and Running Totals

Sign up to unlock
—No data yeteasy
About this challenge

Build closures that remember their own price cap and a running total that updates the caller's variable.

Solved in a browser IDE and graded by tests. Sign up to solve

Arrow Function Rules

Sign up to unlock
—No data yeteasy
About this challenge

Write percent-off, flat-off and minimum-price rules as one-line arrow functions.

Solved in a browser IDE and graded by tests. Sign up to solve

Pluggable Rounding Rules

Sign up to unlock
—No data yeteasy
About this challenge

Accept any callable as a pricing rule and turn an existing rounding function into a Closure.

Solved in a browser IDE and graded by tests. Sign up to solve

Discount Rule Engine

STAR
Solving it completes the module
—No data yeteasy
About this challenge

Compose pricing rules built from closures and arrow functions into a configurable price function with named options.

Solved in a browser IDE and graded by tests. Sign up to solve

We use cookies that are necessary to run Staffcoder, and optional analytics cookies to see which pages get used. Analytics stays off unless you accept. Read our Cookie Policy.