Jump to content
Rtrix

Problema Javascript

Recommended Posts

Posted
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));

}

}

  • Upvote 1
Posted
daca nu ma insel variabilele in javascript sunt salvate ca si arrayuri de caractere, deci ajunge sa faci var

Bineî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.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...