Skip to content

Instantly share code, notes, and snippets.

View rajatjain-21's full-sized avatar
💭
Alive in the world of code

Rajat Jain rajatjain-21

💭
Alive in the world of code
View GitHub Profile
import React, { useState, useCallback } from "react";
import "./styles.css";
import { debounce } from "lodash";
export default function App() {
const [countryName, setCountryName] = useState("");
const [countries, setCountries] = useState([]);
const [error, setError] = useState(null);
const [loading, setLoading] = useState(false);
function curry(func, length = func.length) {
// passing a second paramenter as the number of arguments
// passed to the function
return function (...args) {
if (args.length >= length) {
// if the function call contains arguments which are
// greater than or equal to the max, just the return the func
return func(...args);
} else {
// otherwise call the curry again, binding the already
// Method for creation of array
function array(...arguments) {
let arr = Object.create(array.prototype);
Object.defineProperty(arr, "length", {
value: 0,
enumerable: false,
writable: true
})
for(let i=0;i<arguments.length;i++) {
// Function to be called on click
const mainFunc = () => {
console.log("Called me?😃");
}
const oncifyHelper = () => {
let clickCount = 0;
const oncifyHelperInner = (func) => {
if(clickCount===0) {
func();
@rajatjain-21
rajatjain-21 / partition.js
Created September 7, 2020 17:19
This is a custom method to partition any array based on the logic provided
/**
* A function that partitions an array based on the passed logic
* @param arr The array to be partitioned
* @param callback The logic function to base the partition on
*/
const partition = (arr, callback) => {
// The result object which will ultimately have two properties
// positive and negative
const result = {};
arr.forEach((item, index) => {