w3resource logo

CoffeeScript exercises

CoffeeScript function: Extract unique characters from a string

CoffeeScript Function : Exercise-20 with Solution

Write a CoffeeScript function to extract unique characters from a string.

Example string : "thequickbrownfoxjumpsoverthelazydog"
Expected Output : "thequickbrownfxjmpsvlazydg"

Solution :

HTML Code :

<!DOCTYPE html>
  <meta charset="utf-8">
  <title>JS Bin</title>


CoffeeScript Code :

unique_char = (str1) ->
  str = str1
  uniql = ''
  x = 0
  while x < str.length
    if uniql.indexOf(str.charAt(x)) == -1
      uniql += str[x]

console.log unique_char('thequickbrownfoxjumpsoverthelazydog')

Live Demo :

JS Bin

Post your code through Disqus :

Join our Question Answer community to learn and share your programming knowledge.

Help the community:

PHP: Loop

JavaScript: Delete duplicates in an array

Oracle: Round the number