Loading...
More JavaScript Posts
// `date` is a `Date` objectconst formatYmd = date => date.toISOString().slice(0, 10);// ExampleformatYmd(new Date()); // 2020-05-06
let nums = [1,2,3,1]var containsDuplicate = function(nums) {let obj = {};for(let i =0; i< nums.length; i++){if(obj[nums[i]]){obj[nums[i]] += 1;return true;}else{obj[nums[i]] = 1;}}return false;};console.log(containsDuplicate(nums));
//JavaScript program to swap two variables//take input from the userslet a = prompt('Enter the first variable: ');let b = prompt('Enter the second variable: ');//using destructuring assignment[a, b] = [b, a];console.log(`The value of a after swapping: ${a}`);console.log(`The value of b after swapping: ${b}`);
import { configureStore } from "@reduxjs/toolkit";import { combineReducers } from "redux";import profile from "./profile";import auth from "./auth";import alert from "./alert";const reducer = combineReducers({profile,auth,alert,});const store = configureStore({ reducer });export default store;
if (process.env.NODE_ENV === "production") {app.use(express.static("client/build"));app.get("*", (req, res) => {res.sendFile(path.resolve(__dirname, "client", "build", "index.html"));});}
const binarySearch = (arr, item) => {let l = 0,r = arr.length - 1;while (l <= r) {const mid = Math.floor((l + r) / 2);const guess = arr[mid];if (guess === item) return mid;if (guess > item) r = mid - 1;else l = mid + 1;}return -1;};binarySearch([1, 2, 3, 4, 5], 1); // 0binarySearch([1, 2, 3, 4, 5], 5); // 4binarySearch([1, 2, 3, 4, 5], 6); // -1