Skip to content

#293 Prevent Changes

Adam Kubiś edited this page Oct 28, 2026 · 1 revision

293 Prevent Changes

The police send you an electronic statement for you to sign.

As you begin to sign, an error pops up.Apparently, they sent you a protected document.

This challenge is a bit different as the function you are given already contains some code that you should not change or remove.

Also, don't do a return statement, it is already included.

Your task is, given an object, prevent changes to that object.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/293 Prevent Changes.js"

Assertions are kept alongside the implementation and throw on failure. A successful run exits with code 0. Run every exercise with npm test or both lint and tests with npm run check.

Current implementation and tests

This is the complete executable file, including its imports and inline test cases. Run it from the repository, not as an isolated file copied out of the wiki. Line endings and trailing whitespace are normalized; executable tokens are unchanged.

//The police send you an electronic statement for you to sign.
//As you begin to sign, an error pops up.Apparently, they sent you a protected document.
//This challenge is a bit different as the function you are given already contains some code that you should not change or remove.
//Also, don't do a return statement, it is already included.
//Your task is, given an object, prevent changes to that object.
function preventChanges(obj) {
	// write your code here
	Object.freeze(obj)
	// don't use a return statement
    // non-strict mode dont need to use try catch, but strict mode will throw an error if you try to change a frozen object

	// DON'T CHANGE OR REMOVE THE LINES BELOW
	try {
	obj.noChanges = false;
	obj.signature = "whatever";
	} catch { }

	return obj;
}
import { assertEquals } from '../testHelper.js';
assertEquals(preventChanges({ noChanges: true }), { noChanges: true })

Clone this wiki locally