PracHub
QuestionsPremiumCoachesLearningGuidesInterview Prep
|Home/Coding & Algorithms/Sap

Implement JavaScript utility and API functions

Last updated: Mar 29, 2026

Quick Overview

This question evaluates JavaScript fundamentals including string and numeric operations, array transformation and grouping, functional concepts such as currying and variadic arguments, and asynchronous HTTP interactions with a REST API.

  • medium
  • Sap
  • Coding & Algorithms
  • Software Engineer

Implement JavaScript utility and API functions

Company: Sap

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: medium

Interview Round: Technical Screen

You are given a small JavaScript coding exercise with a local dataset `authors` and access to the public Pokémon API. Assume `authors` is an array of objects shaped like: ```js // authors = [ // { firstName: string, lastName: string, nationality: string }, // ... // ] ``` Implement the following functions (you may use modern JavaScript/TypeScript style, and you may use `async/await` for async functions): ## 1) Basic functions 1. **`strConcat(a, b)`** - Concatenate two strings and return the result. 2. **`sum(x, y)`** - Return the sum of two numbers. ## 2) Working with the `authors` array 3. **`authorNames()`** - Return an array of each author’s full name. - Example output shape: ```js ["Robert Frost", "Philip Dick", ...] ``` 4. **`authorsAreAuthors()`** - Return a single sentence listing all author full names, followed by `" are authors."`. - Example format: - `"Robert Frost, Philip Dick, ... are authors."` - Use sensible punctuation for lists (commas; optional Oxford comma is acceptable). 5. **`americanAuthors()`** - Return a sentence listing only authors whose `nationality` is `"American"`, followed by `" are American authors."`. - Example: - `"Robert Frost, Emily Dickinson, and Philip Dick are American authors."` 6. **`authorNationality()`** - Group authors by `nationality` and return a dictionary/object of this shape: ```js { French: { authors: ["Albert Camus", ...], count: 2 }, American: { authors: ["Robert Frost", ...], count: 3 }, ... } ``` - `authors` should be full-name strings. - `count` should match the number of authors for that nationality. ## 3) JavaScript feature questions 7. **`altSum(x)(y)`** - Implement a curried function where calling `altSum(x)(y)` returns `x + y`. 8. **`nSum(...nums)`** - Implement a function that accepts any number of numeric arguments and returns their total. - Example: `nSum(1, 2, 3, 4) === 10`. ## 4) Pokémon API (network requests) Use the public API at `https://pokeapi.co/`. 9. **`getPokemon()`** - Fetch the first 10 Pokémon from the API endpoint: - `GET https://pokeapi.co/api/v2/pokemon?limit=10` - Return an array of objects containing only: ```js [{ name, url }, ...] ``` 10. **`displayPokemon()`** - Fetch the first 10 Pokémon (via `getPokemon()`), then fetch each Pokémon’s detail URL. - Return an array of objects shaped like: ```js [ { name, height, weight, img // from sprites.front_default }, ... ] ``` ### Notes - Keep return types consistent. - Handle empty lists gracefully. - For API calls, you may fetch sequentially or concurrently (as long as the output is correct).

Quick Answer: This question evaluates JavaScript fundamentals including string and numeric operations, array transformation and grouping, functional concepts such as currying and variadic arguments, and asynchronous HTTP interactions with a REST API.

Sap logo
Sap
Feb 1, 2026, 12:00 AM
Software Engineer
Technical Screen
Coding & Algorithms
1
0
Loading...

You are given a small JavaScript coding exercise with a local dataset authors and access to the public Pokémon API.

Assume authors is an array of objects shaped like:

// authors = [
//   { firstName: string, lastName: string, nationality: string },
//   ...
// ]

Implement the following functions (you may use modern JavaScript/TypeScript style, and you may use async/await for async functions):

1) Basic functions

  1. strConcat(a, b)
    • Concatenate two strings and return the result.
  2. sum(x, y)
    • Return the sum of two numbers.

2) Working with the authors array

  1. authorNames()
    • Return an array of each author’s full name.
    • Example output shape:
      ["Robert Frost", "Philip Dick", ...]
      
  2. authorsAreAuthors()
    • Return a single sentence listing all author full names, followed by " are authors." .
    • Example format:
      • "Robert Frost, Philip Dick, ... are authors."
    • Use sensible punctuation for lists (commas; optional Oxford comma is acceptable).
  3. americanAuthors()
    • Return a sentence listing only authors whose nationality is "American" , followed by " are American authors." .
    • Example:
      • "Robert Frost, Emily Dickinson, and Philip Dick are American authors."
  4. authorNationality()
    • Group authors by nationality and return a dictionary/object of this shape:
      {
        French: {
          authors: ["Albert Camus", ...],
          count: 2
        },
        American: {
          authors: ["Robert Frost", ...],
          count: 3
        },
        ...
      }
      
    • authors should be full-name strings.
    • count should match the number of authors for that nationality.

3) JavaScript feature questions

  1. altSum(x)(y)
    • Implement a curried function where calling altSum(x)(y) returns x + y .
  2. nSum(...nums)
    • Implement a function that accepts any number of numeric arguments and returns their total.
    • Example: nSum(1, 2, 3, 4) === 10 .

4) Pokémon API (network requests)

Use the public API at https://pokeapi.co/.

  1. getPokemon()
    • Fetch the first 10 Pokémon from the API endpoint:
      • GET https://pokeapi.co/api/v2/pokemon?limit=10
    • Return an array of objects containing only:
      [{ name, url }, ...]
      
  2. displayPokemon()
  • Fetch the first 10 Pokémon (via getPokemon() ), then fetch each Pokémon’s detail URL.
  • Return an array of objects shaped like:
    [
      {
        name,
        height,
        weight,
        img // from sprites.front_default
      },
      ...
    ]
    

Notes

  • Keep return types consistent.
  • Handle empty lists gracefully.
  • For API calls, you may fetch sequentially or concurrently (as long as the output is correct).

Submit Your Answer to Earn 20XP

Sign in to leave a comment

Loading comments...

Browse More Questions

More Coding & Algorithms•More Sap•More Software Engineer•Sap Software Engineer•Sap Coding & Algorithms•Software Engineer Coding & Algorithms
PracHub

Master your tech interviews with 8,000+ real questions from top companies.

Product

  • Questions
  • Learning Tracks
  • Interview Guides
  • Resources
  • Premium
  • For Universities
  • Student Access

Browse

  • By Company
  • By Role
  • By Category
  • Topic Hubs
  • SQL Questions
  • Compare Platforms
  • Discord Community

Support

  • support@prachub.com
  • (916) 541-4762

Legal

  • Privacy Policy
  • Terms of Service
  • About Us

© 2026 PracHub. All rights reserved.