How to resolve the algorithm Top rank per group step by step in the zkl programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Top rank per group step by step in the zkl programming language

Table of Contents

Problem Statement

Find the top   N   salaries in each department,   where   N   is provided as a parameter. Use this data as a formatted internal data structure (adapt it to your language-native idioms, rather than parse at runtime), or identify your external data source:

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Top rank per group step by step in the zkl programming language

Source code in the zkl programming language

fcn setAppend(d,[(key,data)]){ d[key]=d.find(key,T).append(data) } //-->(key,(data,data...))

fcn topNsalaries(n){
   File("data.txt").pump(setAppend.fp(data:=D()),fcn(line){ //-->Dictionary(dept:salaries)
      line=line.strip().split(",");
      T(line[-1],line[-2]); //-->(dept,salary)
   });
   dss:=data.pump(List,fcn([(dept,ss)],N){ //-->(dept,(salaries), dept...)
      T(dept).append(ss.sort()[-N,*].reverse());
   }.fp1(n)).sort(fcn(a,b){a[0]
   foreach d,ss in (dss){
      "%s: %s".fmt(d,ss.concat(",")).println();
   }
}(3);

  

You may also check:How to resolve the algorithm Greyscale bars/Display step by step in the RapidQ programming language
You may also check:How to resolve the algorithm XML/DOM serialization step by step in the Kotlin programming language
You may also check:How to resolve the algorithm Display a linear combination step by step in the Rust programming language
You may also check:How to resolve the algorithm Sorting algorithms/Bead sort step by step in the Sidef programming language
You may also check:How to resolve the algorithm Polyspiral step by step in the XPL0 programming language