previous

page 2

next
my countries.html
<script src='countries.js'></script>
<script>
for (var i=0;i<countries.length;i++) {
var c0=countries[i]; // eg 'LAOS'
var letters=c0.split(''); // eg ['L','A','O','S']
var arr=[]; // for storing the set
for (var j=0;j<letters.length;j++) {
var l=letters[j]; // eg 'L'
for (k=0;k<countries.length;k++) {
var c=countries[k]; // eg 'ALGERIA'
var first_letter=c.split('')[0]; // eg 'A'
if (l==first_letter) { // success
arr.push(c);
break; // move on to the next letter
}
}
}
// arr = (eg) ['LEBANON','ALGERIA','OMAN','SUDAN']
// prepare for display on the screen
var s='[';
var t=',';
for (var j=0;j<arr.length;j++) {
if (j==(arr.length-1)) t='],<br>'; // last one
s=s+"'"+arr[j]+"'"+t;
}
document.write(s);
}
</script>
previous
next