Skip to content

Instantly share code, notes, and snippets.

View shohagcsediu's full-sized avatar
💻
Coding

Mohammad Shohag shohagcsediu

💻
Coding
View GitHub Profile
@shohagcsediu
shohagcsediu / No duplicate sorted array.js
Last active November 22, 2022 17:04
Write a Javascript function named fixArray() that will take an array as an argument and return an array that has no duplicates and with elements in ascending order. // Testing code // Define your function fixArray() first let arr = [ 3, 26, 1, 2, 3, 44, 57, 87, 1 ]; let fixedArr = fixArray(arr); console.log(fixedArr); // result should be [1, 2, …
function fixArray(arr) {
let filtered = arr.filter((item, index) => arr.indexOf(item) === index);
return filtered.sort(function(a, b){return a-b})
}
let arr = [ 3, 26, 1, 2, 3, 44, 57, 87, 1 ];
let fixedArr = fixArray(arr);
console.log(fixedArr);
import React, { useState, useEffect } from "react";
export const DateTime = () => {
var [date, setDate] = useState(new Date());
useEffect(() => {
var timer = setInterval(() => setDate(new Date()), 1000);
return function cleanup() {
clearInterval(timer);
}