Skip to content

Commit

Permalink
key value naming fixes and namespace name change
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomhausen committed Jul 23, 2024
1 parent 23907f7 commit 16c4f42
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions dictionary.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit 16c4f42

Please sign in to comment.