Advertisement
dabidabidesh

Letters Combinations

Mar 19th, 2020
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //02. Letters Combinations
  2. function lettersCombinations(arg) {
  3.  
  4.   let char1 = arg.shift()
  5.   let char2 = arg.shift()
  6.   let char3 = arg.shift()
  7.  
  8.   let code1 = char1.charCodeAt(0)
  9.   let code2 = char2.charCodeAt(0)
  10.   let code3 = char3.charCodeAt(0)
  11.  
  12.   let output = ''
  13.   let counter = 0
  14.   for (i = code1; i <= code2; i++)
  15.     for (j = code1; j <= code2; j++)
  16.       for (k = code1; k <= code2; k++)
  17.         if (i != code3 && j != code3 && k != code3) {
  18.           counter++
  19.           output += `${String.fromCharCode(i)}${String.fromCharCode(j)}${String.fromCharCode(k)} `
  20.         }
  21.   console.log(`${output}${counter}`)
  22. }
  23. lettersCombinations([
  24.   'a',
  25.   'c',
  26.   'b'
  27. ])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement