From 16c4f42e544eeb912414a656613a3cb96b6993de Mon Sep 17 00:00:00 2001 From: Tom Moran <62551154+Tomhausen@users.noreply.github.com> Date: Tue, 23 Jul 2024 16:35:13 +0100 Subject: [PATCH] key value naming fixes and namespace name change --- dictionary.ts | 18 +++++++++--------- test.ts | 6 +++--- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/dictionary.ts b/dictionary.ts index e49de2e..4bfb86f 100644 --- a/dictionary.ts +++ b/dictionary.ts @@ -3,7 +3,7 @@ //% icon="\uf240" //% blockGap=8 block="Dictionary" //% groups='["Create", "Edit", "Retrieve", "String"]' -namespace Dictionary { +namespace dictionary { export class Dictionary { private keys: any[] @@ -70,17 +70,17 @@ namespace Dictionary { } } - public replaceValue(key: any, newValue: any): void { - let index = this.keys.indexOf(key); + public replaceValue(value: any, newValue: any): void { + let index = this.values.indexOf(value); if (index != -1) { this.values[index] = newValue; } } - public replaceKey(key: any, newKey: any): void { - let index = this.keys.indexOf(key); + public replaceKey(value: any, newKey: any): void { + let index = this.values.indexOf(value); if (index != -1) { - this.values[index] = newKey; + this.keys[index] = newKey; } } @@ -172,12 +172,12 @@ namespace Dictionary { return d.get_keys_list() } - //% block="%d replace value at %key with %newValue" + //% block="%d replace %value with %newValue" //% blockId="replaceValue" //% group="Edit" //% weight=100 - export function replaceValue(d: Dictionary, key: any, newValue: any): void { - d.replaceValue(key, newValue) + export function replaceValue(d: Dictionary, value: any, newValue: any): void { + d.replaceKey(value, newValue) } //% block="%d replace key at %value with %key" diff --git a/test.ts b/test.ts index 3ced76b..491b72f 100644 --- a/test.ts +++ b/test.ts @@ -7,9 +7,9 @@ replaceValue(1,5) console.log(mylist) -let dict = Dictionary.create(["word"], [1]) -Dictionary.replaceValue(dict, "word", 2) -console.log(Dictionary.get_values_list(dict)) +let dict = dictionary.create(["word"], [1]) +dictionary.replaceValue(dict, "word", 2) +console.log(dictionary.get_values_list(dict)) function replaceValue(value: any, newValue: any): void {