fork download
  1. process.stdin.resume();
  2. process.stdin.setEncoding('utf8');
  3.  
  4. /**
  5.  * Menggunakan JSDOC karena tidak ada Typescript di ideone.com.
  6.  * Solusi ini menggunakan Node.js.
  7.  *
  8.  * @param {string} kataPertama
  9.  * @param {string} kataKedua
  10.  * @returns {boolean}
  11.  */
  12. function punyaHuruf(kataPertama, kataKedua) {
  13. if (typeof kataPertama !== 'string' || typeof kataKedua !== 'string') {
  14. return false;
  15. }
  16.  
  17. kataPertama = kataPertama.trim().toLowerCase();
  18. kataKedua = kataKedua.trim().toLowerCase();
  19.  
  20. if (kataPertama === '' || kataKedua === '') {
  21. return false;
  22. }
  23.  
  24. for (const huruf of kataPertama) {
  25. if (!kataKedua.includes(huruf)) {
  26. return false;
  27. }
  28. }
  29.  
  30. return true;
  31. }
  32.  
  33. // console.log(punyaHuruf('cat', 'antarctica'));
  34. // console.log(punyaHuruf('cat', 'australia'));
  35. // console.log(punyaHuruf('cat', 'ANTARCTICA'));
Success #stdin #stdout 0.04s 42596KB
stdin
Standard input is empty
stdout
Standard output is empty