getCharacters

mail@pastecode.io avatar
unknown
javascript
a year ago
862 B
9
Indexable
Never

/*
  @input: an array of strings where each item contains multiple types of characters
  Description: Filter only characters of each item, and join them together by a space 
  @output: a string
*/
const getCharacters = (arr) => {
  let result = "";
  for (let i=0; i<arr.length; i++) {
    const str = arr[i];
    let temp = '';
    for (let j=0; j<str.length; j++) {
      // if the character is ranged from a-z or A-Z (not any special character)
      if ((str[j] <= 'z' && str[j] >= 'a') || (str[j] <= 'Z' && str[j] >= 'A')) {
        temp += str[j].toUpperCase();
      }
    }
    result += temp;

    // the last item doesn't have a space
    if (i < arr.length-1) {
      result += ' ';
    }
  }
  return result;
}

console.log(getCharacters(['"B$u$i$ld"', '"$t$$h$e"', '"N$e$x$t"', '"E$$ra"', '"$$o$f$"', '"S$$of$t$wa$r$e"', '"De$$ve$l$op$me$n$t"']));