Skip to content

#167 Testing KKN

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

167 Testing KKN

Write a function that returns true if k^k == n for input (n, k) and return false otherwise.

Current source and tests | Catalog | Testing and tooling

Run this solution

From the cloned repository root, after installing dependencies:

node "Edabit/167 Testing KKN.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.

//Write a function that returns true if k^k == n for input (n, k) and return false otherwise.
function kToK(n, k) {
    return Math.pow(k, k) === n;
}
import { assertEquals } from '../testHelper.js';
assertEquals(kToK(4, 2), true)
assertEquals(kToK(387420489, 9), true)
assertEquals(kToK(302875106592253, 13), true)

assertEquals(kToK(3124, 5), false)
assertEquals(kToK(17, 3), false)
assertEquals(kToK(823544, 7), false)

Clone this wiki locally