Rtrix Posted October 2, 2014 Report Posted October 2, 2014 Write a new program which inputs a string and then prints the characters from that string in alphabetical order “substring” and “indexOf” methods" Tips? Quote
H3xoR Posted October 2, 2014 Report Posted October 2, 2014 Tips?function Program() { //citim sirul var input = prompt("Write a string"); //parcurgem fiecare liteza de la a la z (ne asumam ca sirul citit contine doar litere mici) for (var i = 'a'.charCodeAt(0), j = 'z'.charCodeAt(0); i <= j; i++) { //preluam indexul curent al caracterului i (a-z) din sirul citit folosind functia indexOf var index_of_char = input.indexOf(String.fromCharCode(i)); //daca exista acest caracter atunci //il afisam din sirul citit folosind functia substring if (index_of_char != -1) console.log(input.substring(index_of_char, index_of_char + 1)); }} 1 Quote
dragos1412 Posted October 9, 2014 Report Posted October 9, 2014 daca nu ma insel variabilele in javascript sunt salvate ca si arrayuri de caractere, deci ajunge sa faci var Quote
H3xoR Posted October 9, 2014 Report Posted October 9, 2014 daca nu ma insel variabilele in javascript sunt salvate ca si arrayuri de caractere, deci ajunge sa faci varBineîn?eles c? se poate rescrie „programul” într-o manier? mult mai bun? ?i mai simpl? îns? asta presupune s? nu respect?m cerin?a. Cite?te postul ini?ial, se cere indexOf ?i substring. Quote