2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								title: ABC Problem
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								id: 594810f028c0303b75339acc
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								challengeType: 5
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								---
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Description
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'description' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > You are given a collection of ABC blocks (e.g., childhood alphabet blocks). There are 20 blocks with two letters on each block. A complete alphabet is guaranteed amongst all sides of the blocks. The sample collection of blocks:< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (B O)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (X K)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (D Q)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (C P)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (N A)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (G T)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (R E)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (T G)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (Q D)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (F S)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (J W)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (H U)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (V I)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (A N)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (O B)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (E R)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (F S)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (L Y)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (P C)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > (Z M)< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > Some rules to keep in mind:< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Once a letter on a block is used, that block cannot be used again.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The function should be case-insensitive.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< p > Implement a function that takes a string (word) and determines whether the word can be spelled with the given collection of blocks.< / p >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Instructions
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'instructions' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Tests
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'tests' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```yml
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								tests:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord</ code >  is a function.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(typeof canMakeWord === 'function', '< code > canMakeWord< / code >  is a function.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord</ code >  should return a boolean.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(typeof canMakeWord('hi') === 'boolean', '< code > canMakeWord< / code >  should return a boolean.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("bark")</ code >  should return true.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(canMakeWord(words[0]), '< code > canMakeWord("bark")< / code >  should return true.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("BooK")</ code >  should return false.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(!canMakeWord(words[1]), '< code > canMakeWord("BooK")< / code >  should return false.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("TReAT")</ code >  should return true.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(canMakeWord(words[2]), '< code > canMakeWord("TReAT")< / code >  should return true.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("COMMON")</ code >  should return false.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(!canMakeWord(words[3]), '< code > canMakeWord("COMMON")< / code >  should return false.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("squAD")</ code >  should return true.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(canMakeWord(words[4]), '< code > canMakeWord("squAD")< / code >  should return true.');
							 
						 
					
						
							
								
									
										
										
										
											2018-10-04 14:37:37 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  -  text: < code > canMakeWord("conFUSE")</ code >  should return true.
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								    testString: assert(canMakeWord(words[5]), '< code > canMakeWord("conFUSE")< / code >  should return true.');
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Challenge Seed
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'challengeSeed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'js-seed' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function canMakeWord (word) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  // Good luck!
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								### After Test
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< div  id = 'js-teardown' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
									
										
										
										
											2018-10-20 21:02:47 +03:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								const words = ['bark', 'BooK', 'TReAT', 'COMMON', 'squAD', 'conFUSE'];
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / div >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Solution
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< section  id = 'solution' >  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```js
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								function canMakeWord (word) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const characters = 'BO XK DQ CP NA GT RE TG QD FS JW HU VI AN OB ER FS LY PC ZM';
							 
						 
					
						
							
								
									
										
										
										
											2018-10-02 15:02:53 +01:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								  const blocks = characters.split(' ').map(pair => pair.split(''));
							 
						 
					
						
							
								
									
										
										
										
											2018-09-30 23:01:58 +01:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const letters = [...word.toUpperCase()];
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  let length = letters.length;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  const copy = new Set(blocks);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  letters.forEach(letter => {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    for (let block of copy) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      const index = block.indexOf(letter);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      if (index !== -1) {
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        length--;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        copy.delete(block);
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								        break;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								      }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								    }
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  });
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								  return !length;
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								}
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								< / section >