A simple TypeScript typed array text note manager to add remove and display notes with no external dependencies ideal for learning basic array functions.
// Typed array text note manager
// Typed array to store notes
let note: string[] = [];
/**
* Adds a new note to the array
* @param nuovaNota - text of the note to add
*/
function aggiungiNota(nuovaNota: string): void {
note.push(nuovaNota);
}
/**
* Removes a note from the array given the index
* @param indice - position of the note to remove
* @returns true if removal occurred, false if index invalid
*/
function rimuoviNota(indice: number): boolean {
if (indice >= 0 && indice < note.length) {
note.splice(indice, 1);
return true;
}
return false;
}
/**
* Returns a copy of the notes array
* @returns array of strings containing all notes
*/
function visualizzaNote(): string[] {
return [...note]; // returns copy for safety
}
// Usage example:
aggiungiNota("Prima nota");
aggiungiNota("Seconda nota");
console.log("Current notes:", visualizzaNote());
rimuoviNota(0);
console.log("Notes after removal:", visualizzaNote());// Typed array text note manager
// Typed array to store notes
let note: string[] = [];
/**
* Adds a new note to the array
* @param nuovaNota - text of the note to add
*/
function aggiungiNota(nuovaNota: string): void {
note.push(nuovaNota);
}
/**
* Removes a note from the array given the index
* @param indice - position of the note to remove
* @returns true if removal occurred, false if index invalid
*/
function rimuoviNota(indice: number): boolean {
if (indice >= 0 && indice < note.length) {
note.splice(indice, 1);
return true;
}
return false;
}
/**
* Returns a copy of the notes array
* @returns array of strings containing all notes
*/
function visualizzaNote(): string[] {
return [...note]; // returns copy for safety
}
// Example usage to test the note manager
aggiungiNota("First note");
aggiungiNota("Second note");
console.log("Current notes:", visualizzaNote());
rimuoviNota(0);
console.log("Notes after removal:", visualizzaNote());TypeScript (development environment)
Typed array to store notes (string[])
Functions to: add note, remove note by index, display all notes
DEPENDENCIES: no external, only standard TypeScript
CONFIG: no external configuration needed