Ad
Code
Diff
  • export function findTheLongestWord (sentence?: string): string{
      // You Can Code Below Here  
        if (sentence === undefined) {
            return 'gaboleh undefined'
        }
      
        if (sentence === null) {
            return 'gaboleh null'
        }
      
        if (typeof sentence !== 'string') {
           return 'harus string'
        }
    
        if (sentence.trim() === "") {
            return 'gaboleh kosong'
        }
    
        const split = sentence.split(/\s+/);
        let terpanjang = "";
        let panjang = 0;
        let multi = false;
    
        for (const row of split) {
            if (row.length > panjang) {
                terpanjang = row;
                panjang = row.length;
                multi = false;
            } else if (row.length === panjang) {
                multi = true;
            }
        }
    
        if (multi) {
            return "no longest word found";
        } else {
            return `${terpanjang}: ${panjang} chars`;
        }
    }
    
    findTheLongestWord()
    findTheLongestWord("I love Nagatech")
    findTheLongestWord("Programmer use Typescript")
    findTheLongestWord("Determine the Injustice")
    findTheLongestWord("Nagatech Sistem Integrator")
    findTheLongestWord("NGTC")
    findTheLongestWord("Kamu ska Typescript")
    • export function findTheLongestWord (sentence?: string): string{
    • // You Can Code Below Here
    • return ``
    • }
    • if (sentence === undefined) {
    • return 'gaboleh undefined'
    • }
    • if (sentence === null) {
    • return 'gaboleh null'
    • }
    • if (typeof sentence !== 'string') {
    • return 'harus string'
    • }
    • if (sentence.trim() === "") {
    • return 'gaboleh kosong'
    • }
    • const split = sentence.split(/\s+/);
    • let terpanjang = "";
    • let panjang = 0;
    • let multi = false;
    • for (const row of split) {
    • if (row.length > panjang) {
    • terpanjang = row;
    • panjang = row.length;
    • multi = false;
    • } else if (row.length === panjang) {
    • multi = true;
    • }
    • }
    • if (multi) {
    • return "no longest word found";
    • } else {
    • return `${terpanjang}: ${panjang} chars`;
    • }
    • }
    • findTheLongestWord()
    • findTheLongestWord("I love Nagatech")
    • findTheLongestWord("Programmer use Typescript")
    • findTheLongestWord("Determine the Injustice")
    • findTheLongestWord("Nagatech Sistem Integrator")
    • findTheLongestWord("NGTC")
    • findTheLongestWord("Kamu ska Typescript")
Code
Diff
  • interface ListOfBoxes {
      code: string;
      bomb?: boolean;
      boxes?: ListOfBoxes[];
    }
    
    export function findTheBomb (listOfBoxes: ListOfBoxes [], path: string[] = []): string | null {
      // You Can Code Below Here  
      if(listOfBoxes.length > 0){
        for (const box of listOfBoxes) {
            const newPath = [...path, box.code];
            if (box.bomb) {
                return newPath.join(" > ");
            }
            if (box.boxes) {
                const found = findTheBomb(box.boxes, newPath);
                if (found) {
                    return found;
                }
            }
        }
        return null;
      }else{
        return "No Boxes No Bomb!"
      }
    }
    
    const listBoxes1: ListOfBoxes [] = [
      {
        code: "B1",
        boxes: [
          {
            code: "B1.1"
          },
          {
            code: "B1.2"
          }
        ]
      },
      {
        code: "B2",
        boxes: [
          {
            code: "B2.1",
            boxes: [
              {
                code: "B2.1.1"
              },
              {
                code: "B2.1.2",
                bomb: true
              }
            ]
          },
          {
            code: "B2.2"
          }
        ]
      }
    ]
    const listBoxes2: ListOfBoxes [] = [
      {
        "code": "B1.2",
        "boxes": [
          {
            "code": "B1.2.2",
            "boxes": [
              {
                "code": "B1.2.2.6"
              }
            ]
          },
          {
            "code": "B1.2.7"
          },
          {
            "code": "B1.2.4"
          },
          {
            "code": "B1.2.0"
          },
          {
            "code": "B1.2.9",
            "boxes": [
              {
                "code": "B1.2.9.0",
                "bomb": true,
              }
            ]
          }
        ]
      },
      {
        "code": "B2.8",
        "boxes": [
          {
            "code": "B2.8.0"
          },
          {
            "code": "B2.8.7"
          },
          {
            "code": "B2.8.6"
          },
          {
            "code": "B2.8.3"
          }
        ]
      },
      {
        "code": "B3.6",
        "boxes": [
          {
            "code": "B3.6.5"
          },
          {
            "code": "B3.6.7",
            "boxes": [
              {
                "code": "B3.6.7.9"
              }
            ]
          }
        ]
      }
    ]
    const listBoxes3: ListOfBoxes [] = [
      {
        "code": "B1.6",
        "boxes": [
          {
            "code": "B1.6.9"
          },
          {
            "code": "B1.6.2"
          }
        ]
      },
      {
        "code": "B2.4",
        "boxes": [
          {
            "code": "B2.4.0"
          },
          {
            "code": "B2.4.3",
            "boxes": [
              {
                "code": "B2.4.3.9",
                "bomb": true
              }
            ]
          },
          {
            "code": "B2.4.7"
          }
        ]
      }
    ]
    
    findTheBomb([])
    findTheBomb(listBoxes1);
    findTheBomb(listBoxes2);
    findTheBomb(listBoxes3);
    • interface ListOfBoxes {
    • code: string,
    • bomb?: boolean,
    • boxes?: ListOfBoxes[]
    • code: string;
    • bomb?: boolean;
    • boxes?: ListOfBoxes[];
    • }
    • export function findTheBomb (listOfBoxes: ListOfBoxes[]): string{
    • export function findTheBomb (listOfBoxes: ListOfBoxes [], path: string[] = []): string | null {
    • // You Can Code Below Here
    • return ``
    • }
    • if(listOfBoxes.length > 0){
    • for (const box of listOfBoxes) {
    • const newPath = [...path, box.code];
    • if (box.bomb) {
    • return newPath.join(" > ");
    • }
    • if (box.boxes) {
    • const found = findTheBomb(box.boxes, newPath);
    • if (found) {
    • return found;
    • }
    • }
    • }
    • return null;
    • }else{
    • return "No Boxes No Bomb!"
    • }
    • }
    • const listBoxes1: ListOfBoxes [] = [
    • {
    • code: "B1",
    • boxes: [
    • {
    • code: "B1.1"
    • },
    • {
    • code: "B1.2"
    • }
    • ]
    • },
    • {
    • code: "B2",
    • boxes: [
    • {
    • code: "B2.1",
    • boxes: [
    • {
    • code: "B2.1.1"
    • },
    • {
    • code: "B2.1.2",
    • bomb: true
    • }
    • ]
    • },
    • {
    • code: "B2.2"
    • }
    • ]
    • }
    • ]
    • const listBoxes2: ListOfBoxes [] = [
    • {
    • "code": "B1.2",
    • "boxes": [
    • {
    • "code": "B1.2.2",
    • "boxes": [
    • {
    • "code": "B1.2.2.6"
    • }
    • ]
    • },
    • {
    • "code": "B1.2.7"
    • },
    • {
    • "code": "B1.2.4"
    • },
    • {
    • "code": "B1.2.0"
    • },
    • {
    • "code": "B1.2.9",
    • "boxes": [
    • {
    • "code": "B1.2.9.0",
    • "bomb": true,
    • }
    • ]
    • }
    • ]
    • },
    • {
    • "code": "B2.8",
    • "boxes": [
    • {
    • "code": "B2.8.0"
    • },
    • {
    • "code": "B2.8.7"
    • },
    • {
    • "code": "B2.8.6"
    • },
    • {
    • "code": "B2.8.3"
    • }
    • ]
    • },
    • {
    • "code": "B3.6",
    • "boxes": [
    • {
    • "code": "B3.6.5"
    • },
    • {
    • "code": "B3.6.7",
    • "boxes": [
    • {
    • "code": "B3.6.7.9"
    • }
    • ]
    • }
    • ]
    • }
    • ]
    • const listBoxes3: ListOfBoxes [] = [
    • {
    • "code": "B1.6",
    • "boxes": [
    • {
    • "code": "B1.6.9"
    • },
    • {
    • "code": "B1.6.2"
    • }
    • ]
    • },
    • {
    • "code": "B2.4",
    • "boxes": [
    • {
    • "code": "B2.4.0"
    • },
    • {
    • "code": "B2.4.3",
    • "boxes": [
    • {
    • "code": "B2.4.3.9",
    • "bomb": true
    • }
    • ]
    • },
    • {
    • "code": "B2.4.7"
    • }
    • ]
    • }
    • ]
    • findTheBomb([])
    • findTheBomb(listBoxes1);
    • findTheBomb(listBoxes2);
    • findTheBomb(listBoxes3);
Code
Diff
  • export function filteringDataMoreThanEqual (data: number[], comparator: number): string{
      const hasil = data.filter(nilai => nilai >= comparator);  
      return String(hasil);
    }
    
    const point: number[] = [20, 10, 100, 40, 5, 50];
    filteringDataMoreThanEqual(point,10)
    filteringDataMoreThanEqual(point,40)
    filteringDataMoreThanEqual(point,100)
    • export function filteringDataMoreThanEqual (data: number[], comparator: number): string{
    • return String(data);
    • }
    • const hasil = data.filter(nilai => nilai >= comparator);
    • return String(hasil);
    • }
    • const point: number[] = [20, 10, 100, 40, 5, 50];
    • filteringDataMoreThanEqual(point,10)
    • filteringDataMoreThanEqual(point,40)
    • filteringDataMoreThanEqual(point,100)
Code
Diff
  • export interface iType {
      subject: string,
      point: number
    }
    
      const data: iType[] = [
        {
            subject: "IPA",
            point: 70,
        },
        {
            subject: "MTK",
            point: 65
        }
      ];
    
    export function valueResult (data: iType[]): number {
      let value = 0;
      // You Can Code Below Here
        const totalPoint = data.reduce((total, item) => total + item.point, 0);
        const totalData = data.length;
        
        value = totalPoint / totalData;
      
      return value;
    }
    
    
      valueResult(data)
    • export interface iType {
    • subject: string,
    • point: number
    • }
    • const data: iType[] = [
    • {
    • subject: "IPA",
    • point: 70,
    • },
    • {
    • subject: "MTK",
    • point: 65
    • }
    • ];
    • export function valueResult (data: iType[]): number {
    • let value = 0;
    • // You Can Code Below Here
    • const totalPoint = data.reduce((total, item) => total + item.point, 0);
    • const totalData = data.length;
    • value = totalPoint / totalData;
    • return value;
    • }
    • }
    • valueResult(data)
Code
Diff
  • export interface iType{
        id: number,
        name: string,
      }
      
      const datas: iType[] = [
        {
            id: 1,
            name: "Manny"
        },
        {
            id: 2,
            name: "Danny"
        },
        {
            id: 3,
            name: "Socciella"
        },
      ];
      export function findData ( data: iType[],selectedData: number): iType | undefined {
        return data.find(item => item.id === selectedData);
      }
      
      
      findData(datas,1);
      findData(datas,2);
      
    • export interface iType{
    • id: number,
    • name: string,
    • }
    • export function findData (data: iType[], selectedData: number): iType {
    • // You Can Code Here
    • id: number,
    • name: string,
    • }
    • }
    • const datas: iType[] = [
    • {
    • id: 1,
    • name: "Manny"
    • },
    • {
    • id: 2,
    • name: "Danny"
    • },
    • {
    • id: 3,
    • name: "Socciella"
    • },
    • ];
    • export function findData ( data: iType[],selectedData: number): iType | undefined {
    • return data.find(item => item.id === selectedData);
    • }
    • findData(datas,1);
    • findData(datas,2);
Code
Diff
  • export function takeANumber (text: string): number {
      // Don't Change This Variable
      let result: number = parseInt(text.slice(1));
      
      return result;
    }
    
    takeANumber("B0002")
    
    takeANumber("B0000001")
    
    takeANumber("B0000004")
    • export function takeANumber (text: string): number {
    • // Don't Change This Variable
    • let result: number = 0;
    • // You Can Code Below Here
    • let result: number = parseInt(text.slice(1));
    • return result;
    • }
    • }
    • takeANumber("B0002")
    • takeANumber("B0000001")
    • takeANumber("B0000004")
Code
Diff
  • export function takeFirstWord (text: string) {
      const split: string[] = text.split('').filter(char => char === char.toUpperCase());
      const join: string = split.join('');
      return join.replace(/\s/g, "")
    }
    
    takeFirstWord("I Love Typescript")
    • export function takeFirstWord (text: string) {
    • }
    • const split: string[] = text.split('').filter(char => char === char.toUpperCase());
    • const join: string = split.join('');
    • return join.replace(/\s/g, "")
    • }
    • takeFirstWord("I Love Typescript")