Tell us what works and what could be better. We read every submission.
@aanaedu·3 public vizzes
This example contrasts array and object data structures for grouping colored balls by category. It uses plain JavaScript objects and arrays to represent a basket of balls, then demonstrates two problems: first, grouping balls into fixed red, green, and blue containers with explicit if-statements; second, scaling to an arbitrary number of categories using a dictionary (object) that dynamically creates new containers when an unseen color appears. The code shows how object keys map to category names, enabling flexible retrieval via bracket notation like `categoryObj[type]`.
This example demonstrates JavaScript Promise chains for handling asynchronous operations. It shows two scenarios: a primer where sequential API calls resolve and reject at different timeouts, and a currency conversion flow that fetches exchange rates from a simulated service before processing a card payment. The code uses native `Promise` objects, `setTimeout` for delays, and `.then()` callbacks to manage dependent operations. Data flows from mocked responses containing currency rates and payment statuses, with success and error paths logged to the console.
This example demonstrates higher-order array methods in JavaScript using sample datasets of orders and animals. It shows how `map` transforms an array into a new array of the same size, `filter` keeps only elements matching a true condition, and `reduce` accumulates values from an array into a single result. The code defines an orders array with amount properties and an animals array with name and type properties, then illustrates each method with commented-out examples that log transformed results to the console.