deuxieme essai transforme pour transformer les chiffres arabes en chiffres romains

function hitboleloute(num) {//1e parenthese // Create a bidimentionnal list that contain successives degree of a same // principle. "use strict"; var superlist = [["a", "I", "X", "C", "M"], ["b", 'V', 'L', "D"], ["c", "X", "C", "M"]]; //the first step num to string. var letter1 = num.toString(); console.log("la premiere operation sur le nombre: ", letter1); //the second step string to array var letter2 = letter1.split(''); var l = letter2.length; console.log("premiere apparition de letter2 ", letter2);//!1e affiche //the third step looping through array and replace digit-string by letter //of symbolic value. function exchange(array, val1, val2) {array[array.indexOf(val1)] = val2; return array; } for(i = 0; i < l; i++ ) {// 2e parenthese var item = letter2[i]; console.log("item avant d'etre transforme ", item); if(item === '1') {exchange(letter2,'1', 'a')} else if (item === '2') {exchange(letter2, '2', 'aa'); console.log("premier changement ", item)} else if (item === '3') {exchange(letter2,'3', "aaa")} else if (item === '4') {exchange(letter2, '4', "ab")} else if (item === '5') {exchange(letter2,'5', "b")} else if (item === '6') {exchange(letter2,'6',"ba")} else if (item === '7') {exchange(letter2,'7', "baa")} else if (item === '8') {exchange(letter2,'8', "baaa")} else if (item === '9') {exchange(letter2,'9', "ac")} else {exchange(item,'0', '')} console.log("item ", item); console.log("letter2 ",letter2); }//2e parenthese closed function changeLetters(mot, a, b) { mot.charAt(mot.indexOf(a)) = b; } for (x = 0; x<4; x++) {//new 2e parenthese console.log("x ", x); for (j = l -x; j > -1; j --) {//3e parenthese var jtem = letter2[j];//chaque jtem est un mot de 3 lettres. //si l'index de ce mot est l - x, on va puiser les //remplacents dans l'element numerote x de la superliste //4e parenthese if (jtem !==null && jtem!== undefined && jtem.charAt(k) === 'a') { changeLetters(jtem,'a', superlist[0][x]); console.log(jtem); } else if (jtem !==null && jtem!== undefined && jtem.charAt(k) === 'b') { changeLetters(jtem, 'b', superlist[1][x]); console.log(jtem); } else if (jtem !==null && jtem!== undefined && jtem.charAt(k) === 'c') { changeLetters(jtem, 'c', superlist[2][x]); }//4e parenthese closed }//3e parenthese closed }//new 2e parenthese closed //1e parenthese closed // a list of roman numerals return letter2.join(''); } hitboleloute(124);

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.