This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function isExist(target, array) { | |
let sorted = array.sort((a, b) => a - b); | |
let midPoint = Math.floor(sorted.length / 2); | |
if (sorted[midPoint] === target) { | |
console.log('exist'); | |
} else if (sorted.length <= 1) { | |
console.log('not exist'); | |
} else if (sorted[midPoint] < target) { | |
isExist(target, sorted.slice(midPoint, sorted.length)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function findDupe(str) { | |
let hash = {} | |
for (let x of str) { | |
hash[x] ? hash[x] += 1 : hash[x] = 1; | |
if (hash[x] === 2) return x | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// simple function to check duplicate exist | |
function dupe(arr) { | |
return [...new Set(arr)].length === arr.length | |
} | |
// BOW | |
const misuh_warning = [ | |
'asu','4su','45u','a5u', | |
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 58. Length of last word | |
* https://leetcode.com/problems/length-of-last-word/ | |
*/ | |
const lengthOfLastWord = s => { | |
s = s.trim().split(' '); | |
const word = s[s.length - 1]; | |
return word.length; | |
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ref https://codepen.io/Pestov/pen/BLpgm | |
const tree = { | |
root: { | |
root1: { name: "Kakek", deceased: true }, | |
root2: { name: "Nenek", deceased: false }, | |
childs: [ | |
{ | |
name: "Anak 1", | |
spouse: [{ name: "Istri anak 1", deceased: false, divorced: true }], |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use client"; | |
import { X } from "lucide-react"; | |
import React, { useEffect } from "react"; | |
import { createPortal } from "react-dom"; | |
import ReactFocusLock from "react-focus-lock"; | |
export default function AccessibleDialogOrModal() { | |
return ( | |
<> |
OlderNewer