CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/npm-babel-plugin-transform-es2015-computed-properties

Babel plugin that compiles ES2015 computed properties to ES5-compatible code

88

1.07x
Overview
Eval results
Files

task.mdevals/scenario-4/

Custom Iterator Implementation

Build a JavaScript module that creates objects with custom iteration behavior using Symbols and computed property syntax.

Requirements

Create a module that exports a function createIterableRange(start, end, step) which returns an object that can be iterated using a for...of loop. The object should:

  • Use Symbol-based computed properties to define custom iteration behavior
  • Generate numbers from start to end (inclusive) with the given step size
  • Support the standard JavaScript iterator protocol
  • Use Symbol.iterator as a computed property key
  • Handle edge cases where step is negative or zero (throw an error for step === 0)

Test Cases

  • Creating an iterable range from 1 to 5 with step 1 yields [1, 2, 3, 4, 5] @test
  • Creating an iterable range from 0 to 10 with step 2 yields [0, 2, 4, 6, 8, 10] @test
  • Creating an iterable range from 5 to 1 with step -1 yields [5, 4, 3, 2, 1] @test
  • Creating an iterable range with step 0 throws an error @test

Implementation

@generates

API

/**
 * Creates an iterable object that generates a range of numbers.
 *
 * @param {number} start - The starting value of the range
 * @param {number} end - The ending value of the range (inclusive)
 * @param {number} step - The increment/decrement between values
 * @returns {Object} An iterable object with Symbol.iterator as a computed property
 * @throws {Error} Throws an error if step is 0
 */
function createIterableRange(start, end, step) {
  // IMPLEMENTATION HERE
}

module.exports = { createIterableRange };

Dependencies { .dependencies }

@babel/plugin-transform-computed-properties { .dependency }

Transforms computed properties with Symbol keys to ES5-compatible code.

Install with Tessl CLI

npx tessl i tessl/npm-babel-plugin-transform-es2015-computed-properties

tile.json