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 memoize< | |
| Response, | |
| ProvidedFunctionType extends (...args: any[]) => Response | |
| >( | |
| computeExpensiveValue: ProvidedFunctionType, | |
| keyFunction: (...args: any[]) => string, | |
| cachingFunction?: () => Map<string, Response> | |
| ): ProvidedFunctionType { | |
| // if no caching object is provided, instanciate a Map instead. | |
| const hashMap = cachingFunction ? cachingFunction() : new Map(); |
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
| export class SuperArray<Data> extends Array { | |
| static from<Data>(input: Data[]): SuperArray<Data> { | |
| return new SuperArray(input); | |
| } | |
| constructor(input: any[]) { | |
| super(input.length); | |
| input.forEach((element, index) => { | |
| this[index] = element; | |
| }) |
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 arrayOfNumbers(n) { | |
| return Array.from(Array(n).keys()) | |
| .map((x) => ++x) | |
| } | |
| function fizzBuzz(n) { | |
| const mutators = [ | |
| {key: 3, val:"Fizz"}, | |
| {key:5, val: "Buzz"} |
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
| import java.io.File; | |
| import java.io.IOException; | |
| import java.io.PrintWriter; | |
| import java.nio.file.Files; | |
| import java.nio.file.Paths; | |
| import java.util.stream.Collectors; | |
| import java.util.stream.Stream; | |
| public class AnagramFinder { |
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
| const queryString = (year, goals, page) => { | |
| const rootUrl = 'https://jsonmock.hackerrank.com'; | |
| const queryString = `/api/football_matches?year=${year}&team1goals=${goals}&team2goals=${goals}&page=${page}`; | |
| return rootUrl + queryString; | |
| } |
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
| async function getNumDraws(year) { | |
| const arrayOfScores = Array.from(Array(11).keys()); | |
| return Promise.all(arrayOfScores.map(item => getTiesCountByNumberOfGoals(year, item))) | |
| .then(drawsCountForEachScore => { | |
| return drawsCountForEachScore.reduce((x, y) => x + y, 0); | |
| }) | |
| } |
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
| async function getTiesCountByNumberOfGoals(year, goals) { | |
| const [gamesOnFirstPage, numberOfPages] = await getNumOfGamesFromPage(year, goals, 0); | |
| const pageArray = Array.from(Array(numberOfPages).keys()).filter((e) => e !== 0); | |
| return Promise.all( | |
| [ | |
| gamesOnFirstPage, | |
| ...pageArray.map(page => getNumOfGamesFromPage(year, goals, page)) | |
| ]) |
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
| const fetch = require('node-fetch'); | |
| async function getNumOfGamesFromPage(year, goals, page) { | |
| const response = await fetch(queryString(year, goals, page)) | |
| .catch(err => console.log("get error " + err.message)); | |
| const json = await response.json(); | |
| if (page === 0) { | |
| return [json.data.length, json.total_pages]; |
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
| const fetch = require('node-fetch'); | |
| const queryString = (year, goals, page) => { | |
| const rootUrl = 'https://jsonmock.hackerrank.com'; | |
| const queryString = `/api/football_matches?year=${year}&team1goals=${goals}&team2goals=${goals}&page=${page}`; | |
| return rootUrl + queryString; | |
| } | |
| async function getNumOfGamesFromPage(year, goals, page) { | |
| const response = await fetch(queryString(year, goals, page)) |