Im trying to make a music program to transpose chords.
string[] cifra = { “C”, “D”, “E”, “F”, “G”, “A”, “B” };
I think the funtion to swap one time is:
for(int i=0;i<cifra.Lenght-1;i++)
{
temp = cifra[i];
cifra[i] = cifra[i+1];
cifra[n + 1] = temp;
}
The result should be
{ “D”, “E”, “F”, “G”, “A”, “B”, “C” };
Hi @Cafony - welcome to the forums! If you are looking for a more general swap mechanism, this tutorial should help you out:
Here is the code:
let myData = ["a", "b", "c", "d", "e", "f", "g"];
function swap(input, index_A, index_B) {
let temp = input[index_A];
input[index_A] = input[index_B];
input[index_B] = temp;
}
swap(myData, 2, 5);
console.log(myData); // a b f d e c g
Creating engaging and entertaining content for designers and developers since 1998.