▸case-05 Write a TypeScript class method `processPayment` that accepts a `PaymentMethod` enum (CREDIT_CARD, PAYPAL, BANK_TRANSFER). Switch on the method to process it. In the default case, throw a generic Error('Invalid payment method'). | fail→pass | 3,898 | 4,787 | +23% | 1 | 1 | 0% | 885 | 1,116 | +26% | 0 | 0 | — |
▸case-01 Write a TypeScript Redux reducer function for a shopping cart. The state is an array of items. The action is a discriminated union with `type: 'ADD' | 'REMOVE' | 'CLEAR'`. Use a switch statement on the action type. In the default case, throw an Error with the message 'Unknown action' to handle unexpected values. | fail→pass | 6,029 | 5,832 | -3% | 1 | 1 | 0% | 1,487 | 1,433 | -4% | 0 | 0 | — |
▸case-02 Create a React functional component in TypeScript that receives a `status` prop, which is a union of `'idle' | 'loading' | 'success'`. Render different UI for each using a switch statement. For the default fallback, return a generic `<div>Unexpected State</div>`. | fail→pass | 3,663 | 4,731 | +29% | 1 | 1 | 0% | 801 | 1,097 | +37% | 0 | 0 | — |
▸case-03 Write a TypeScript function `parseResponse` that takes an `ApiResponse` object. The object has a `kind` property based on an enum `ResponseKind` (SUCCESS, FAILURE, TIMEOUT). Switch on the `kind`. If an unrecognized kind is passed, log a warning to the console and return null in the default block. | fail→pass | 5,143 | 5,894 | +15% | 1 | 1 | 0% | 1,084 | 1,351 | +25% | 0 | 0 | — |
▸case-04 Implement a TypeScript function `visitNode` that takes an AST node, which is a discriminated union with a `type` field ('Literal', 'Identifier', 'BinaryExpression'). Use a switch statement to process each type. For the default case, throw a SyntaxError indicating an unhandled node type. | pass→pass | 6,659 | 6,122 | -8% | 1 | 1 | 0% | 1,606 | 1,334 | -17% | 0 | 0 | — |
▸case-06 Create a TypeScript function `handleWsEvent` that takes a WebSocket event object. The event is a discriminated union with an `eventType` property ('JOIN', 'LEAVE', 'MESSAGE'). Switch on `eventType`. For any unknown event types in the default case, simply return false. | fail→pass | 7,904 | 5,391 | -32% | 1 | 1 | 0% | 1,799 | 1,294 | -28% | 0 | 0 | — |
▸case-07 Write a TypeScript function `calculateArea` that takes a `Shape` discriminated union (`kind: 'circle' | 'square' | 'rectangle'`). Use a switch statement to calculate the area. In the default case, throw an Error stating 'Unknown shape'. | fail→pass | 4,026 | 3,371 | -16% | 1 | 1 | 0% | 1,012 | 884 | -13% | 0 | 0 | — |
▸case-08 Implement a TypeScript function `getAnimalSound` that accepts an `AnimalSpecies` enum (DOG, CAT, BIRD). Switch on the species to return a sound string. For the default case, return the string 'Unknown sound'. | fail→pass | 3,317 | 4,590 | +38% | 1 | 1 | 0% | 790 | 962 | +22% | 0 | 0 | — |
▸case-09 Write a TypeScript function `routeVehicle` that takes a `Vehicle` discriminated union (`class: 'car' | 'truck' | 'motorcycle'`). Switch on the class to return a routing path. In the default case, throw an Error('Unroutable vehicle'). | pass→fail | 4,857 | 4,703 | -3% | 1 | 1 | 0% | 1,008 | 1,111 | +10% | 0 | 0 | — |
▸case-14 Create a TypeScript function `executeFsOp` that takes an `FsOperation` enum (READ, WRITE, DELETE). Switch on the operation. In the default case, throw an Error('Operation not permitted'). | fail→pass | 3,563 | 5,157 | +45% | 1 | 1 | 0% | 773 | 1,154 | +49% | 0 | 0 | — |
▸case-10 Create a TypeScript function `exportDocument` that takes an `ExportFormat` enum (PDF, DOCX, HTML). Switch on the format to call the respective export logic. In the default case, throw an Error('Unsupported format'). | fail→pass | 4,519 | 4,454 | -1% | 1 | 1 | 0% | 1,044 | 1,042 | -0% | 0 | 0 | — |
▸case-11 Write a TypeScript function `dispatchNotification` that accepts a `Notification` discriminated union (`type: 'email' | 'sms' | 'push'`). Switch on the type to send the notification. For the default case, log an error and return false. | fail→pass | 6,334 | 6,750 | +7% | 1 | 1 | 0% | 1,493 | 1,540 | +3% | 0 | 0 | — |
▸case-12 Implement a TypeScript function `getPermissions` that takes a `UserRole` enum (ADMIN, EDITOR, VIEWER). Switch on the role to return an array of permission strings. In the default case, return an empty array. | fail→pass | 3,524 | 4,757 | +35% | 1 | 1 | 0% | 863 | 1,066 | +24% | 0 | 0 | — |
▸case-13 Write a TypeScript function `runMigration` that takes a `MigrationCommand` discriminated union (`action: 'up' | 'down' | 'status'`). Switch on the action. For the default case, throw an Error('Invalid migration command'). | pass→pass | 4,984 | 4,532 | -9% | 1 | 1 | 0% | 1,071 | 1,038 | -3% | 0 | 0 | — |
▸case-15 Write a TypeScript function `resolveThemeColor` that accepts a `ThemeVariant` discriminated union (`mode: 'light' | 'dark' | 'system'`). Switch on the mode to return a hex color string. For the default case, return '#FFFFFF'. | fail→fail | 5,212 | 6,202 | +19% | 1 | 1 | 0% | 1,171 | 1,309 | +12% | 0 | 0 | — |
▸case-16 Implement a TypeScript function `trackEvent` that takes a `TrackEventType` enum (PAGE_VIEW, CLICK, SUBMIT). Switch on the event type to send data to the analytics server. In the default case, do nothing and just break. | fail→pass | 5,402 | 5,292 | -2% | 1 | 1 | 0% | 1,193 | 1,280 | +7% | 0 | 0 | — |
▸case-17 Write a TypeScript function `executePipelineStep` that takes a `PipelineStep` discriminated union (`stepKind: 'build' | 'test' | 'deploy'`). Switch on the stepKind. For the default case, throw an Error('Unknown pipeline step'). | pass→pass | 4,261 | 5,255 | +23% | 1 | 1 | 0% | 967 | 1,225 | +27% | 0 | 0 | — |
▸case-18 Create a TypeScript function `calculateDiscount` that accepts a `DiscountType` enum (PERCENTAGE, FIXED_AMOUNT, FREE_SHIPPING). Switch on the type to calculate the new price. In the default case, return the original price. | fail→pass | 5,906 | 5,714 | -3% | 1 | 1 | 0% | 1,334 | 1,367 | +2% | 0 | 0 | — |
▸case-19 Write a TypeScript function `updateGameState` that takes a `GameState` discriminated union (`state: 'menu' | 'playing' | 'gameover'`). Switch on the state to update the game loop. For the default case, throw an Error('Invalid game state'). | pass→pass | 5,262 | 6,248 | +19% | 1 | 1 | 0% | 1,150 | 1,292 | +12% | 0 | 0 | — |
▸case-20 Write a TypeScript function `processCommand` that takes a plain `string` argument representing a CLI command. Use a switch statement to handle 'start', 'stop', and 'restart'. For any other string in the default case, throw an Error('Unknown command'). | pass→fail | 3,261 | 9,653 | +196% | 1 | 1 | 0% | 702 | 2,041 | +191% | 0 | 0 | — |
▸case-21 Write a TypeScript function `getHttpStatusMessage` that takes a `number` representing an HTTP status code. Switch on 200, 404, and 500 to return their standard string messages. For the default case, return the string 'Unknown Status'. | pass→fail | 2,595 | 14,070 | +442% | 1 | 1 | 0% | 651 | 3,103 | +377% | 0 | 0 | — |
▸case-22 Write a TypeScript function `printLog` that takes a `LogLevel` enum (INFO, WARN, ERROR). Use an if/else if/else chain (do not use a switch statement) to print the log to the console. In the final else block, throw an Error('Invalid log level'). | pass→pass | 3,853 | 3,363 | -13% | 1 | 1 | 0% | 920 | 760 | -17% | 0 | 0 | — |