Skip to main content

containsDuplicate

0 likes • Nov 19, 2022 • 0 views
JavaScript
Loading...

More JavaScript Posts

LeetCode Two Sum

CHS
0 likes • Sep 13, 2023 • 2 views
JavaScript
/**
* @param {number[]} nums
* @param {number} target
* @return {number[]}
*/
var twoSum = function(nums, target) {
for(let i = 0; i < nums.length; i++) {
for(let j = 0; j < nums.length; j++) {
if(nums[i] + nums[j] === target && i !== j) {
return [i, j]
}
}
}
};

Bitwise XOR operator

0 likes • Nov 19, 2022 • 0 views
JavaScript
//JavaScript program to swap two variables
//take input from the users
let a = prompt('Enter the first variable: ');
let b = prompt('Enter the second variable: ');
// XOR operator
a = a ^ b
b = a ^ b
a = a ^ b
console.log(`The value of a after swapping: ${a}`);
console.log(`The value of b after swapping: ${b}`);

React - Lifting State

CHS
0 likes • Jan 25, 2023 • 2 views
JavaScript
export const Main = () => {
const [title, setTitle] = useState('');
return (
<ChildComponent
title={title}
onChange={e => setTitle(e.target.value)}
/>
);
};
export const ChildComponent = ({ title, onChange }) => {
return (
<Box component="form" onSubmit={() => {}} noValidate mt={5}>
<TextField
fullWidth
id="title"
label="Title"
name="title"
autoComplete="title"
autoFocus
color="primary"
variant="filled"
InputLabelProps={{ shrink: true }}
value={title}
onChange={onChange}
/>
</Box>
);
};

Invert Binary Tree

0 likes • Oct 15, 2022 • 6 views
JavaScript
var invertTree = function(root) {
const reverseNode = node => {
if (node == null) {
return null
}
reverseNode(node.left);
reverseNode(node.right);
let holdLeft = node.left;
node.left = node.right;
node.right = holdLeft;
return node;
}
return reverseNode(root);
};

LeetCode Contains Duplicate

CHS
0 likes • Sep 13, 2023 • 2 views
JavaScript
/**
* @param {number[]} nums
* @return {boolean}
*/
var containsDuplicate = function(nums) {
return new Set(nums).size !== nums.length
};

Convert data to yyyy mm dd format

0 likes • Nov 19, 2022 • 1 view
JavaScript
// `date` is a `Date` object
const formatYmd = date => date.toISOString().slice(0, 10);
// Example
formatYmd(new Date()); // 2020-05-06