fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. // your code goes here
  5. class Kamus {
  6. constructor() {
  7. this.data = {};
  8. }
  9.  
  10. tambah(kata, sinonimArray) {
  11. if (!this.data[kata]) {
  12. this.data[kata] = new Set();
  13. }
  14.  
  15. sinonimArray.forEach((s) => this.data[kata].add(s));
  16. }
  17.  
  18. ambilSinonim(kata) {
  19. if (!this.data[kata]) {
  20. return null;
  21. }
  22.  
  23. const sinonim = Array.from(this.data[kata]);
  24.  
  25. if (sinonim.length === 0) {
  26. return [kata];
  27. }
  28.  
  29. return sinonim;
  30. }
  31. }
  32.  
  33. const kamus = new Kamus();
  34. kamus.tambah('big', ['large', 'great']);
  35. kamus.tambah('big', ['huge', 'fat']);
  36. kamus.tambah('huge', ['enormous', 'gigantic']);
  37.  
  38. console.log(kamus.ambilSinonim('big'));
  39. console.log(kamus.ambilSinonim('huge'));
  40. console.log(kamus.ambilSinonim('gigantic'));
  41. console.log(kamus.ambilSinonim('colossal'));
  42.  
Success #stdin #stdout 0.05s 41284KB
stdin
Standard input is empty
stdout
[ 'large', 'great', 'huge', 'fat' ]
[ 'enormous', 'gigantic' ]
null
null